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