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.voicemailstatus; 18 19 import android.database.Cursor; 20 import android.provider.VoicemailContract.Status; 21 import com.android.dialer.database.VoicemailStatusQuery; 22 23 /** 24 * Interface used by the call log UI to determine what user message, if any, related to voicemail 25 * source status needs to be shown. The messages are returned in the order of importance. 26 * 27 * <p>The implementation of this interface interacts with the voicemail content provider to fetch 28 * statuses of all the registered voicemail sources and determines if any status message needs to be 29 * shown. The user of this interface must observe/listen to provider changes and invoke this class 30 * to check if any message needs to be shown. 31 */ 32 public class VoicemailStatusHelper { 33 34 /** 35 * Returns the number of active voicemail sources installed. 36 * 37 * <p>The number of sources is counted by querying the voicemail status table. 38 * 39 * @param cursor The caller is responsible for the life cycle of the cursor and resetting the 40 * position 41 */ getNumberActivityVoicemailSources(Cursor cursor)42 public int getNumberActivityVoicemailSources(Cursor cursor) { 43 int count = 0; 44 if (!cursor.moveToFirst()) { 45 return 0; 46 } 47 do { 48 if (isVoicemailSourceActive(cursor)) { 49 ++count; 50 } 51 } while (cursor.moveToNext()); 52 return count; 53 } 54 55 /** 56 * Returns whether the source status in the cursor corresponds to an active source. A source is 57 * active if its' configuration state is not NOT_CONFIGURED. For most voicemail sources, only OK 58 * and NOT_CONFIGURED are used. The OMTP visual voicemail client has the same behavior pre-NMR1. 59 * NMR1 visual voicemail will only set it to NOT_CONFIGURED when it is deactivated. As soon as 60 * activation is attempted, it will transition into CONFIGURING then into OK or other error state, 61 * NOT_CONFIGURED is never set through an error. 62 */ isVoicemailSourceActive(Cursor cursor)63 private boolean isVoicemailSourceActive(Cursor cursor) { 64 return cursor.getString(VoicemailStatusQuery.SOURCE_PACKAGE_INDEX) != null 65 && cursor.getInt(VoicemailStatusQuery.CONFIGURATION_STATE_INDEX) 66 != Status.CONFIGURATION_STATE_NOT_CONFIGURED; 67 } 68 } 69