diff options
Diffstat (limited to 'java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java')
-rw-r--r-- | java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java b/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java index 9df45c211..16bfe704d 100644 --- a/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java +++ b/java/com/android/dialer/voicemailstatus/VoicemailStatusHelper.java @@ -17,8 +17,10 @@ package com.android.dialer.voicemailstatus; import android.database.Cursor; +import android.net.Uri; import android.provider.VoicemailContract.Status; -import com.android.dialer.database.VoicemailStatusQuery; +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 @@ -29,40 +31,66 @@ import com.android.dialer.database.VoicemailStatusQuery; * 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 class VoicemailStatusHelper { +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. - * - * @param cursor The caller is responsible for the life cycle of the cursor and resetting the - * position */ - public int getNumberActivityVoicemailSources(Cursor cursor) { - int count = 0; - if (!cursor.moveToFirst()) { - return 0; + 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; } - do { - if (isVoicemailSourceActive(cursor)) { - ++count; - } - } while (cursor.moveToNext()); - return count; - } - /** - * Returns whether the source status in the cursor corresponds to an active source. A source is - * active if its' configuration state is not NOT_CONFIGURED. For most voicemail sources, only OK - * and NOT_CONFIGURED are used. The OMTP visual voicemail client has the same behavior pre-NMR1. - * NMR1 visual voicemail will only set it to NOT_CONFIGURED when it is deactivated. As soon as - * activation is attempted, it will transition into CONFIGURING then into OK or other error state, - * NOT_CONFIGURED is never set through an error. - */ - private boolean isVoicemailSourceActive(Cursor cursor) { - return cursor.getString(VoicemailStatusQuery.SOURCE_PACKAGE_INDEX) != null - && cursor.getInt(VoicemailStatusQuery.CONFIGURATION_STATE_INDEX) - != Status.CONFIGURATION_STATE_NOT_CONFIGURED; + /** 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; + } } } |