summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail/impl/protocol/VisualVoicemailProtocol.java
blob: a2e94ed773c1b899572cd369a7326a015da29ef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.voicemail.impl.protocol;

import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import com.android.voicemail.impl.ActivationTask;
import com.android.voicemail.impl.DefaultOmtpEventHandler;
import com.android.voicemail.impl.OmtpConstants;
import com.android.voicemail.impl.OmtpEvents;
import com.android.voicemail.impl.OmtpVvmCarrierConfigHelper;
import com.android.voicemail.impl.VoicemailStatus;
import com.android.voicemail.impl.sms.OmtpMessageSender;
import com.android.voicemail.impl.sms.StatusMessage;

public abstract class VisualVoicemailProtocol {

  /** Activation should cause the carrier to respond with a STATUS SMS. */
  public void startActivation(OmtpVvmCarrierConfigHelper config, PendingIntent sentIntent) {
    OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config);
    if (messageSender != null) {
      messageSender.requestVvmActivation(sentIntent);
    }
  }

  public void startDeactivation(OmtpVvmCarrierConfigHelper config) {
    OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config);
    if (messageSender != null) {
      messageSender.requestVvmDeactivation(null);
    }
  }

  public boolean supportsProvisioning() {
    return false;
  }

  public void startProvisioning(
      ActivationTask task,
      PhoneAccountHandle handle,
      OmtpVvmCarrierConfigHelper config,
      VoicemailStatus.Editor editor,
      StatusMessage message,
      Bundle data,
      boolean isCarrierInitiated) {
    // Do nothing
  }

  public void requestStatus(OmtpVvmCarrierConfigHelper config, @Nullable PendingIntent sentIntent) {
    OmtpMessageSender messageSender = ProtocolHelper.getMessageSender(this, config);
    if (messageSender != null) {
      messageSender.requestVvmStatus(sentIntent);
    }
  }

  public abstract OmtpMessageSender createMessageSender(
      Context context,
      PhoneAccountHandle phoneAccountHandle,
      short applicationPort,
      String destinationNumber);

  /**
   * Translate an OMTP IMAP command to the protocol specific one. For example, changing the TUI
   * password on OMTP is XCHANGE_TUI_PWD, but on CVVM and VVM3 it is CHANGE_TUI_PWD.
   *
   * @param command A String command in {@link OmtpConstants}, the exact instance should be used
   *     instead of its' value.
   * @returns Translated command, or {@code null} if not available in this protocol
   */
  public String getCommand(String command) {
    return command;
  }

  public void handleEvent(
      Context context,
      OmtpVvmCarrierConfigHelper config,
      VoicemailStatus.Editor status,
      OmtpEvents event) {
    DefaultOmtpEventHandler.handleEvent(context, config, status, event);
  }

  /**
   * Given an VVM SMS with an unknown {@code event}, let the protocol attempt to translate it into
   * an equivalent STATUS SMS. Returns {@code null} if it cannot be translated.
   */
  @Nullable
  public Bundle translateStatusSmsBundle(
      OmtpVvmCarrierConfigHelper config, String event, Bundle data) {
    return null;
  }
}