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