• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 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.telephony.SmsManager;
23 import com.android.voicemail.impl.OmtpConstants;
24 import com.android.voicemail.impl.TelephonyMangerCompat;
25 import com.android.voicemail.impl.VvmLog;
26 
27 /**
28  * Send client originated OMTP messages to the OMTP server.
29  *
30  * <p>Uses {@link PendingIntent} instead of a call back to notify when the message is sent. This is
31  * primarily to keep the implementation simple and reuse what the underlying {@link SmsManager}
32  * interface provides.
33  *
34  * <p>Provides simple APIs to send different types of mobile originated OMTP SMS to the VVM server.
35  */
36 public abstract class OmtpMessageSender {
37   protected static final String TAG = "OmtpMessageSender";
38   protected final Context context;
39   protected final PhoneAccountHandle phoneAccountHandle;
40   protected final short applicationPort;
41   protected final String destinationNumber;
42 
OmtpMessageSender( Context context, PhoneAccountHandle phoneAccountHandle, short applicationPort, String destinationNumber)43   public OmtpMessageSender(
44       Context context,
45       PhoneAccountHandle phoneAccountHandle,
46       short applicationPort,
47       String destinationNumber) {
48     this.context = context;
49     this.phoneAccountHandle = phoneAccountHandle;
50     this.applicationPort = applicationPort;
51     this.destinationNumber = destinationNumber;
52   }
53 
54   /**
55    * Sends a request to the VVM server to activate VVM for the current subscriber.
56    *
57    * @param sentIntent If not NULL this PendingIntent is broadcast when the message is successfully
58    *     sent, or failed.
59    */
requestVvmActivation(@ullable PendingIntent sentIntent)60   public void requestVvmActivation(@Nullable PendingIntent sentIntent) {}
61 
62   /**
63    * Sends a request to the VVM server to deactivate VVM for the current subscriber.
64    *
65    * @param sentIntent If not NULL this PendingIntent is broadcast when the message is successfully
66    *     sent, or failed.
67    */
requestVvmDeactivation(@ullable PendingIntent sentIntent)68   public void requestVvmDeactivation(@Nullable PendingIntent sentIntent) {}
69 
70   /**
71    * Send a request to the VVM server to get account status of the current subscriber.
72    *
73    * @param sentIntent If not NULL this PendingIntent is broadcast when the message is successfully
74    *     sent, or failed.
75    */
requestVvmStatus(@ullable PendingIntent sentIntent)76   public void requestVvmStatus(@Nullable PendingIntent sentIntent) {}
77 
sendSms(String text, PendingIntent sentIntent)78   protected void sendSms(String text, PendingIntent sentIntent) {
79 
80     VvmLog.v(
81         TAG, String.format("Sending sms '%s' to %s:%d", text, destinationNumber, applicationPort));
82 
83     TelephonyMangerCompat.sendVisualVoicemailSms(
84         context, phoneAccountHandle, destinationNumber, applicationPort, text, sentIntent);
85   }
86 
appendField(StringBuilder sb, String field, Object value)87   protected void appendField(StringBuilder sb, String field, Object value) {
88     sb.append(field).append(OmtpConstants.SMS_KEY_VALUE_SEPARATOR).append(value);
89   }
90 }
91