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