summaryrefslogtreecommitdiffstats
path: root/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java
blob: 16bfe704d2ec00b66ac59fb656b870ddd8507825 (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
/*
 * Copyright (C) 2011 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.dialer.voicemailstatus;

import android.database.Cursor;
import android.net.Uri;
import android.provider.VoicemailContract.Status;
import android.support.annotation.VisibleForTesting;
import java.util.List;

/**
 * Interface used by the call log UI to determine what user message, if any, related to voicemail
 * source status needs to be shown. The messages are returned in the order of importance.
 *
 * <p>The implementation of this interface interacts with the voicemail content provider to fetch
 * statuses of all the registered voicemail sources and determines if any status message needs to be
 * shown. The user of this interface must observe/listen to provider changes and invoke this class
 * to check if any message needs to be shown.
 */
public interface VoicemailStatusHelper {

  /**
   * Returns a list of messages, in the order or priority that should be shown to the user. An empty
   * list is returned if no message needs to be shown.
   *
   * @param cursor The cursor pointing to the query on {@link Status#CONTENT_URI}. The projection to
   *     be used is defined by the implementation class of this interface.
   */
  @VisibleForTesting
  List<StatusMessage> getStatusMessages(Cursor cursor);

  /**
   * Returns the number of active voicemail sources installed.
   *
   * <p>The number of sources is counted by querying the voicemail status table.
   */
  int getNumberActivityVoicemailSources(Cursor cursor);

  @VisibleForTesting
  class StatusMessage {

    /** Package of the source on behalf of which this message has to be shown. */
    public final String sourcePackage;
    /**
     * The string resource id of the status message that should be shown in the call log page. Set
     * to -1, if this message is not to be shown in call log.
     */
    public final int callLogMessageId;
    /**
     * The string resource id of the status message that should be shown in the call details page.
     * Set to -1, if this message is not to be shown in call details page.
     */
    public final int callDetailsMessageId;
    /** The string resource id of the action message that should be shown. */
    public final int actionMessageId;
    /** URI for the corrective action, where applicable. Null if no action URI is available. */
    public final Uri actionUri;

    public StatusMessage(
        String sourcePackage,
        int callLogMessageId,
        int callDetailsMessageId,
        int actionMessageId,
        Uri actionUri) {
      this.sourcePackage = sourcePackage;
      this.callLogMessageId = callLogMessageId;
      this.callDetailsMessageId = callDetailsMessageId;
      this.actionMessageId = actionMessageId;
      this.actionUri = actionUri;
    }

    /** Whether this message should be shown in the call log page. */
    public boolean showInCallLog() {
      return callLogMessageId != -1;
    }

    /** Whether this message should be shown in the call details page. */
    public boolean showInCallDetails() {
      return callDetailsMessageId != -1;
    }
  }
}