1/* 2 * Copyright (C) 2016 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 17package com.android.phone.vvm.omtp.protocol; 18 19import android.annotation.Nullable; 20import android.app.PendingIntent; 21import android.content.Context; 22import android.os.Bundle; 23import android.telecom.PhoneAccountHandle; 24import android.telephony.SmsManager; 25import com.android.phone.VoicemailStatus; 26import com.android.phone.vvm.omtp.ActivationTask; 27import com.android.phone.vvm.omtp.DefaultOmtpEventHandler; 28import com.android.phone.vvm.omtp.OmtpEvents; 29import com.android.phone.vvm.omtp.OmtpVvmCarrierConfigHelper; 30import com.android.phone.vvm.omtp.sms.OmtpMessageSender; 31import com.android.phone.vvm.omtp.sms.StatusMessage; 32 33public abstract class VisualVoicemailProtocol { 34 35 /** 36 * Activation should cause the carrier to respond with a STATUS SMS. 37 */ 38 public void startActivation(OmtpVvmCarrierConfigHelper config, PendingIntent sentIntent) { 39 OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config); 40 if (messageSender != null) { 41 messageSender.requestVvmActivation(sentIntent); 42 } 43 } 44 45 public void startDeactivation(OmtpVvmCarrierConfigHelper config) { 46 OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config); 47 if (messageSender != null) { 48 messageSender.requestVvmDeactivation(null); 49 } 50 } 51 52 public boolean supportsProvisioning() { 53 return false; 54 } 55 56 public void startProvisioning(ActivationTask task, PhoneAccountHandle handle, 57 OmtpVvmCarrierConfigHelper config, VoicemailStatus.Editor editor, StatusMessage message, 58 Bundle data) { 59 // Do nothing 60 } 61 62 public void requestStatus(OmtpVvmCarrierConfigHelper config, 63 @Nullable PendingIntent sentIntent) { 64 OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config); 65 if (messageSender != null) { 66 messageSender.requestVvmStatus(sentIntent); 67 } 68 } 69 70 public abstract OmtpMessageSender createMessageSender(SmsManager smsManager, 71 short applicationPort, String destinationNumber); 72 73 /** 74 * Translate an OMTP IMAP command to the protocol specific one. For example, changing the TUI 75 * password on OMTP is XCHANGE_TUI_PWD, but on CVVM and VVM3 it is CHANGE_TUI_PWD. 76 * 77 * @param command A String command in {@link com.android.phone.vvm.omtp.OmtpConstants}, the exact 78 * instance should be used instead of its' value. 79 * @returns Translated command, or {@code null} if not available in this protocol 80 */ 81 public String getCommand(String command) { 82 return command; 83 } 84 85 public void handleEvent(Context context, OmtpVvmCarrierConfigHelper config, 86 VoicemailStatus.Editor status, OmtpEvents event) { 87 DefaultOmtpEventHandler.handleEvent(context, config, status, event); 88 } 89 90 /** 91 * Given an VVM SMS with an unknown {@code event}, let the protocol attempt to translate it into 92 * an equivalent STATUS SMS. Returns {@code null} if it cannot be translated. 93 */ 94 @Nullable 95 public Bundle translateStatusSmsBundle(OmtpVvmCarrierConfigHelper config, String event, 96 Bundle data) { 97 return null; 98 } 99} 100