1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony.cdma; 18 19 import static com.android.internal.telephony.SmsResponse.NO_ERROR_CODE; 20 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.os.Message; 23 import android.telephony.ServiceState; 24 import android.telephony.TelephonyManager; 25 26 import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails; 27 import com.android.internal.telephony.GsmCdmaPhone; 28 import com.android.internal.telephony.Phone; 29 import com.android.internal.telephony.PhoneConstants; 30 import com.android.internal.telephony.SMSDispatcher; 31 import com.android.internal.telephony.SmsConstants; 32 import com.android.internal.telephony.SmsDispatchersController; 33 import com.android.internal.telephony.SmsHeader; 34 import com.android.internal.telephony.SmsMessageBase; 35 import com.android.internal.telephony.util.SMSDispatcherUtil; 36 import com.android.telephony.Rlog; 37 38 public class CdmaSMSDispatcher extends SMSDispatcher { 39 private static final String TAG = "CdmaSMSDispatcher"; 40 private static final boolean VDBG = false; 41 CdmaSMSDispatcher(Phone phone, SmsDispatchersController smsDispatchersController)42 public CdmaSMSDispatcher(Phone phone, SmsDispatchersController smsDispatchersController) { 43 super(phone, smsDispatchersController); 44 Rlog.d(TAG, "CdmaSMSDispatcher created"); 45 } 46 47 @UnsupportedAppUsage 48 @Override getFormat()49 public String getFormat() { 50 return SmsConstants.FORMAT_3GPP2; 51 } 52 53 /** 54 * Send the SMS status report to the dispatcher thread to process. 55 * @param sms the CDMA SMS message containing the status report 56 */ sendStatusReportMessage(SmsMessage sms)57 public void sendStatusReportMessage(SmsMessage sms) { 58 if (VDBG) Rlog.d(TAG, "sending EVENT_HANDLE_STATUS_REPORT message"); 59 sendMessage(obtainMessage(EVENT_HANDLE_STATUS_REPORT, sms)); 60 } 61 62 @Override handleStatusReport(Object o)63 protected void handleStatusReport(Object o) { 64 if (o instanceof SmsMessage) { 65 if (VDBG) Rlog.d(TAG, "calling handleSmsStatusReport()"); 66 byte[] pdu = ((SmsMessage) o).getPdu(); 67 mSmsDispatchersController.handleSmsStatusReport(SmsConstants.FORMAT_3GPP2, pdu); 68 } else { 69 Rlog.e(TAG, "handleStatusReport() called for object type " + o.getClass().getName()); 70 } 71 } 72 73 @Override shouldBlockSmsForEcbm()74 protected boolean shouldBlockSmsForEcbm() { 75 // We only block outgoing SMS during ECBM when using CDMA. 76 return mPhone.isInEcm() && isCdmaMo() && !isIms(); 77 } 78 79 @Override getSubmitPdu(String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, int priority, int validityPeriod)80 protected SmsMessageBase.SubmitPduBase getSubmitPdu(String scAddr, String destAddr, 81 String message, boolean statusReportRequested, SmsHeader smsHeader, int priority, 82 int validityPeriod) { 83 return SMSDispatcherUtil.getSubmitPduCdma(scAddr, destAddr, message, 84 statusReportRequested, smsHeader, priority); 85 } 86 87 @Override getSubmitPdu(String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested)88 protected SmsMessageBase.SubmitPduBase getSubmitPdu(String scAddr, String destAddr, 89 int destPort, byte[] message, boolean statusReportRequested) { 90 return SMSDispatcherUtil.getSubmitPduCdma(scAddr, destAddr, destPort, message, 91 statusReportRequested); 92 } 93 94 @Override calculateLength(CharSequence messageBody, boolean use7bitOnly)95 protected TextEncodingDetails calculateLength(CharSequence messageBody, boolean use7bitOnly) { 96 return SMSDispatcherUtil.calculateLengthCdma(messageBody, use7bitOnly); 97 } 98 99 /** {@inheritDoc} */ 100 @Override sendSms(SmsTracker tracker)101 public void sendSms(SmsTracker tracker) { 102 int ss = mPhone.getServiceState().getState(); 103 104 Rlog.d(TAG, "sendSms: " 105 + " isIms()=" + isIms() 106 + " mRetryCount=" + tracker.mRetryCount 107 + " mImsRetry=" + tracker.mImsRetry 108 + " mMessageRef=" + tracker.mMessageRef 109 + " mUsesImsServiceForIms=" + tracker.mUsesImsServiceForIms 110 + " SS=" + ss); 111 112 // if sms over IMS is not supported on data and voice is not available... 113 if (!isIms() && ss != ServiceState.STATE_IN_SERVICE) { 114 tracker.onFailed(mContext, getNotInServiceError(ss), NO_ERROR_CODE); 115 return; 116 } 117 118 Message reply = obtainMessage(EVENT_SEND_SMS_COMPLETE, tracker); 119 byte[] pdu = (byte[]) tracker.getData().get("pdu"); 120 121 int currentDataNetwork = mPhone.getServiceState().getDataNetworkType(); 122 boolean imsSmsDisabled = (currentDataNetwork == TelephonyManager.NETWORK_TYPE_EHRPD 123 || (currentDataNetwork == TelephonyManager.NETWORK_TYPE_LTE 124 || currentDataNetwork == TelephonyManager.NETWORK_TYPE_LTE_CA 125 || currentDataNetwork == TelephonyManager.NETWORK_TYPE_NR) 126 && !mPhone.getServiceStateTracker().isConcurrentVoiceAndDataAllowed()) 127 && mPhone.getServiceState().getVoiceNetworkType() 128 == TelephonyManager.NETWORK_TYPE_1xRTT 129 && ((GsmCdmaPhone) mPhone).mCT.mState != PhoneConstants.State.IDLE; 130 131 // sms over cdma is used: 132 // if sms over IMS is not supported AND 133 // this is not a retry case after sms over IMS failed 134 // indicated by mImsRetry > 0 OR 135 // SMS over IMS is disabled because of the network type OR 136 // SMS over IMS is being handled by the ImsSmsDispatcher implementation and has indicated 137 // that the message should fall back to sending over CS. 138 if (0 == tracker.mImsRetry && !isIms() || imsSmsDisabled || tracker.mUsesImsServiceForIms) { 139 if (tracker.mRetryCount == 0 && tracker.mExpectMore) { 140 mCi.sendCdmaSMSExpectMore(pdu, reply); 141 } else { 142 mCi.sendCdmaSms(pdu, reply); 143 } 144 } else { 145 mCi.sendImsCdmaSms(pdu, tracker.mImsRetry, tracker.mMessageRef, reply); 146 // increment it here, so in case of SMS_FAIL_RETRY over IMS 147 // next retry will be sent using IMS request again. 148 tracker.mImsRetry++; 149 } 150 } 151 } 152