1 /*
2  * Copyright (C) 2011 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.dialer.voicemail;
18 
19 import android.database.Cursor;
20 import android.net.Uri;
21 import android.provider.VoicemailContract.Status;
22 
23 import com.google.common.annotations.VisibleForTesting;
24 
25 import java.util.List;
26 
27 /**
28  * Interface used by the call log UI to determine what user message, if any, related to voicemail
29  * source status needs to be shown. The messages are returned in the order of importance.
30  * <p>
31  * The implementation of this interface interacts with the voicemail content provider to fetch
32  * statuses of all the registered voicemail sources and determines if any status message needs to
33  * be shown. The user of this interface must observe/listen to provider changes and invoke
34  * this class to check if any message needs to be shown.
35  */
36 public interface VoicemailStatusHelper {
37     @VisibleForTesting
38     public class StatusMessage {
39         /** Package of the source on behalf of which this message has to be shown.*/
40         public final String sourcePackage;
41         /**
42          * The string resource id of the status message that should be shown in the call log
43          * page. Set to -1, if this message is not to be shown in call log.
44          */
45         public final int callLogMessageId;
46         /**
47          * The string resource id of the status message that should be shown in the call details
48          * page. Set to -1, if this message is not to be shown in call details page.
49          */
50         public final int callDetailsMessageId;
51         /** The string resource id of the action message that should be shown. */
52         public final int actionMessageId;
53         /** URI for the corrective action, where applicable. Null if no action URI is available. */
54         public final Uri actionUri;
55 
StatusMessage(String sourcePackage, int callLogMessageId, int callDetailsMessageId, int actionMessageId, Uri actionUri)56         public StatusMessage(String sourcePackage, int callLogMessageId, int callDetailsMessageId,
57                 int actionMessageId, Uri actionUri) {
58             this.sourcePackage = sourcePackage;
59             this.callLogMessageId = callLogMessageId;
60             this.callDetailsMessageId = callDetailsMessageId;
61             this.actionMessageId = actionMessageId;
62             this.actionUri = actionUri;
63         }
64 
65         /** Whether this message should be shown in the call log page. */
showInCallLog()66         public boolean showInCallLog() {
67             return callLogMessageId != -1;
68         }
69 
70         /** Whether this message should be shown in the call details page. */
showInCallDetails()71         public boolean showInCallDetails() {
72             return callDetailsMessageId != -1;
73         }
74     }
75 
76     /**
77      * Returns a list of messages, in the order or priority that should be shown to the user. An
78      * empty list is returned if no message needs to be shown.
79      * @param cursor The cursor pointing to the query on {@link Status#CONTENT_URI}. The projection
80      *      to be used is defined by the implementation class of this interface.
81      */
82     @VisibleForTesting
getStatusMessages(Cursor cursor)83     public List<StatusMessage> getStatusMessages(Cursor cursor);
84 
85     /**
86      * Returns the number of active voicemail sources installed.
87      * <p>
88      * The number of sources is counted by querying the voicemail status table.
89      */
getNumberActivityVoicemailSources(Cursor cursor)90     public int getNumberActivityVoicemailSources(Cursor cursor);
91 }
92