Files
uabdullah cdcda1a127 Use UI Listeners for querying voicemail status table
Earlier we were using the legacy CallLogQueryHandler for querying the voicemail status table. However we should be using UI Listeners instead in NUI. This CL queries the voicemail status table and returns a list of voicemail status', which are then used to display the corresponding error messages.

This CL also moved VoicemailStatus out of the legacy dialer/database and moves it to dialer/voicemailstatus and ensures that there are no dependencies on the legacy dialer/database in the NUI.

Bug: 73139237
Test: Unit tests
PiperOrigin-RevId: 185321023
Change-Id: Id16ea475b6a52da380fbf8b3590dc75cbcdc370e
2018-02-12 11:42:06 -08:00

72 lines
2.8 KiB
Java

/*
* 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.provider.VoicemailContract.Status;
/**
* Utility 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>This class 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 class must observe/listen to provider changes and invoke this class to check if any message
* needs to be shown.
*/
public final class VoicemailStatusHelper {
private VoicemailStatusHelper() {}
/**
* 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 static int getNumberActivityVoicemailSources(Cursor cursor) {
int count = 0;
if (!cursor.moveToFirst()) {
return 0;
}
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 static boolean isVoicemailSourceActive(Cursor cursor) {
return cursor.getString(VoicemailStatusQuery.SOURCE_PACKAGE_INDEX) != null
// getInt() returns 0 when null
&& !cursor.isNull(VoicemailStatusQuery.CONFIGURATION_STATE_INDEX)
&& cursor.getInt(VoicemailStatusQuery.CONFIGURATION_STATE_INDEX)
!= Status.CONFIGURATION_STATE_NOT_CONFIGURED;
}
}