summaryrefslogtreecommitdiff
path: root/java/com/android/voicemailomtp/protocol/VisualVoicemailProtocol.java
blob: 9ff2ed167e7328a6aa8490fccd8d8c0052c28c56 (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
/*
 * 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.voicemailomtp.protocol;

import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import android.telephony.SmsManager;
import com.android.voicemailomtp.ActivationTask;
import com.android.voicemailomtp.DefaultOmtpEventHandler;
import com.android.voicemailomtp.OmtpEvents;
import com.android.voicemailomtp.OmtpVvmCarrierConfigHelper;
import com.android.voicemailomtp.VoicemailStatus;
import com.android.voicemailomtp.sms.OmtpMessageSender;
import com.android.voicemailomtp.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) {
        // 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 com.android.voicemailomtp.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;
    }
}