1 /* 2 * Copyright (C) 2015 Google Inc. All Rights Reserved. 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 package com.android.voicemail.impl.sms; 17 18 import android.app.PendingIntent; 19 import android.content.Context; 20 import android.support.annotation.Nullable; 21 import android.telecom.PhoneAccountHandle; 22 import android.text.TextUtils; 23 import com.android.voicemail.impl.OmtpConstants; 24 25 /** A implementation of the OmtpMessageSender using the standard OMTP sms protocol. */ 26 public class OmtpStandardMessageSender extends OmtpMessageSender { 27 private final String mClientType; 28 private final String mProtocolVersion; 29 private final String mClientPrefix; 30 31 /** 32 * Creates a new instance of OmtpStandardMessageSender. 33 * 34 * @param applicationPort If set to a value > 0 then a binary sms is sent to this port number. 35 * Otherwise, a standard text SMS is sent. 36 * @param destinationNumber Destination number to be used. 37 * @param clientType The "ct" field to be set in the MO message. This is the value used by the VVM 38 * server to identify the client. Certain VVM servers require a specific agreed value for this 39 * field. 40 * @param protocolVersion OMTP protocol version. 41 * @param clientPrefix The client prefix requested to be used by the server in its MT messages. 42 */ OmtpStandardMessageSender( Context context, PhoneAccountHandle phoneAccountHandle, short applicationPort, String destinationNumber, String clientType, String protocolVersion, String clientPrefix)43 public OmtpStandardMessageSender( 44 Context context, 45 PhoneAccountHandle phoneAccountHandle, 46 short applicationPort, 47 String destinationNumber, 48 String clientType, 49 String protocolVersion, 50 String clientPrefix) { 51 super(context, phoneAccountHandle, applicationPort, destinationNumber); 52 mClientType = clientType; 53 mProtocolVersion = protocolVersion; 54 mClientPrefix = clientPrefix; 55 } 56 57 // Activate message: 58 // V1.1: Activate:pv=<value>;ct=<value> 59 // V1.2: Activate:pv=<value>;ct=<value>;pt=<value>;<Clientprefix> 60 // V1.3: Activate:pv=<value>;ct=<value>;pt=<value>;<Clientprefix> 61 @Override requestVvmActivation(@ullable PendingIntent sentIntent)62 public void requestVvmActivation(@Nullable PendingIntent sentIntent) { 63 StringBuilder sb = new StringBuilder().append(OmtpConstants.ACTIVATE_REQUEST); 64 65 appendProtocolVersionAndClientType(sb); 66 if (TextUtils.equals(mProtocolVersion, OmtpConstants.PROTOCOL_VERSION1_2) 67 || TextUtils.equals(mProtocolVersion, OmtpConstants.PROTOCOL_VERSION1_3)) { 68 appendApplicationPort(sb); 69 appendClientPrefix(sb); 70 } 71 72 sendSms(sb.toString(), sentIntent); 73 } 74 75 // Deactivate message: 76 // V1.1: Deactivate:pv=<value>;ct=<string> 77 // V1.2: Deactivate:pv=<value>;ct=<string> 78 // V1.3: Deactivate:pv=<value>;ct=<string> 79 @Override requestVvmDeactivation(@ullable PendingIntent sentIntent)80 public void requestVvmDeactivation(@Nullable PendingIntent sentIntent) { 81 StringBuilder sb = new StringBuilder().append(OmtpConstants.DEACTIVATE_REQUEST); 82 appendProtocolVersionAndClientType(sb); 83 84 sendSms(sb.toString(), sentIntent); 85 } 86 87 // Status message: 88 // V1.1: STATUS 89 // V1.2: STATUS 90 // V1.3: STATUS:pv=<value>;ct=<value>;pt=<value>;<Clientprefix> 91 @Override requestVvmStatus(@ullable PendingIntent sentIntent)92 public void requestVvmStatus(@Nullable PendingIntent sentIntent) { 93 StringBuilder sb = new StringBuilder().append(OmtpConstants.STATUS_REQUEST); 94 95 if (TextUtils.equals(mProtocolVersion, OmtpConstants.PROTOCOL_VERSION1_3)) { 96 appendProtocolVersionAndClientType(sb); 97 appendApplicationPort(sb); 98 appendClientPrefix(sb); 99 } 100 101 sendSms(sb.toString(), sentIntent); 102 } 103 appendProtocolVersionAndClientType(StringBuilder sb)104 private void appendProtocolVersionAndClientType(StringBuilder sb) { 105 sb.append(OmtpConstants.SMS_PREFIX_SEPARATOR); 106 appendField(sb, OmtpConstants.PROTOCOL_VERSION, mProtocolVersion); 107 sb.append(OmtpConstants.SMS_FIELD_SEPARATOR); 108 appendField(sb, OmtpConstants.CLIENT_TYPE, mClientType); 109 } 110 appendApplicationPort(StringBuilder sb)111 private void appendApplicationPort(StringBuilder sb) { 112 sb.append(OmtpConstants.SMS_FIELD_SEPARATOR); 113 appendField(sb, OmtpConstants.APPLICATION_PORT, mApplicationPort); 114 } 115 appendClientPrefix(StringBuilder sb)116 private void appendClientPrefix(StringBuilder sb) { 117 sb.append(OmtpConstants.SMS_FIELD_SEPARATOR); 118 sb.append(mClientPrefix); 119 } 120 } 121