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