Search in sources :

Example 1 with Voicemail

use of com.android.voicemail.impl.Voicemail in project android_packages_apps_Dialer by LineageOS.

the class ImapHelper method fetchAllVoicemails.

/**
 * Fetch a list of voicemails from the server.
 *
 * @return A list of voicemail objects containing data about voicemails stored on the server.
 */
public List<Voicemail> fetchAllVoicemails() {
    List<Voicemail> result = new ArrayList<Voicemail>();
    Message[] messages;
    try {
        mFolder = openImapFolder(ImapFolder.MODE_READ_WRITE);
        if (mFolder == null) {
            // This means we were unable to successfully open the folder.
            return null;
        }
        // This method retrieves lightweight messages containing only the uid of the message.
        messages = mFolder.getMessages(null);
        for (Message message : messages) {
            // Get the voicemail details (message structure).
            MessageStructureWrapper messageStructureWrapper = fetchMessageStructure(message);
            if (messageStructureWrapper != null) {
                result.add(getVoicemailFromMessageStructure(messageStructureWrapper));
            }
        }
        return result;
    } catch (MessagingException e) {
        LogUtils.e(TAG, e, "Messaging Exception");
        return null;
    } finally {
        closeImapFolder();
    }
}
Also used : Message(com.android.voicemail.impl.mail.Message) MimeMessage(com.android.voicemail.impl.mail.internet.MimeMessage) MessagingException(com.android.voicemail.impl.mail.MessagingException) ArrayList(java.util.ArrayList) Voicemail(com.android.voicemail.impl.Voicemail)

Example 2 with Voicemail

use of com.android.voicemail.impl.Voicemail in project android_packages_apps_Dialer by LineageOS.

the class VoicemailsQueryHelper method oldestVoicemailsOnServer.

/**
 * Find the oldest voicemails that are on the device, and also on the server.
 */
// used for try with resources
@TargetApi(VERSION_CODES.M)
public List<Voicemail> oldestVoicemailsOnServer(int numVoicemails) {
    if (numVoicemails <= 0) {
        Assert.fail("Query for remote voicemails cannot be <= 0");
    }
    String sortAndLimit = "date ASC limit " + numVoicemails;
    try (Cursor cursor = mContentResolver.query(mSourceUri, PROJECTION, ARCHIVED_SELECTION, null, sortAndLimit)) {
        Assert.isNotNull(cursor);
        List<Voicemail> voicemails = new ArrayList<>();
        while (cursor.moveToNext()) {
            final long id = cursor.getLong(_ID);
            final String sourceData = cursor.getString(SOURCE_DATA);
            Voicemail voicemail = Voicemail.createForUpdate(id, sourceData).build();
            voicemails.add(voicemail);
        }
        if (voicemails.size() != numVoicemails) {
            Assert.fail(String.format("voicemail count (%d) doesn't matched expected (%d)", voicemails.size(), numVoicemails));
        }
        return voicemails;
    }
}
Also used : ArrayList(java.util.ArrayList) Voicemail(com.android.voicemail.impl.Voicemail) Cursor(android.database.Cursor) TargetApi(android.annotation.TargetApi)

Example 3 with Voicemail

use of com.android.voicemail.impl.Voicemail in project android_packages_apps_Dialer by LineageOS.

the class OmtpVvmSyncService method download.

private boolean download(ImapHelper imapHelper, PhoneAccountHandle account) {
    List<Voicemail> serverVoicemails = imapHelper.fetchAllVoicemails();
    List<Voicemail> localVoicemails = mQueryHelper.getAllVoicemails(account);
    if (localVoicemails == null || serverVoicemails == null) {
        // Null value means the query failed.
        return false;
    }
    Map<String, Voicemail> remoteMap = buildMap(serverVoicemails);
    // by design (to make space).
    for (int i = 0; i < localVoicemails.size(); i++) {
        Voicemail localVoicemail = localVoicemails.get(i);
        Voicemail remoteVoicemail = remoteMap.remove(localVoicemail.getSourceData());
        // Do not delete voicemails that are archived marked as archived.
        if (remoteVoicemail == null) {
            mQueryHelper.deleteNonArchivedFromDatabase(localVoicemail);
        } else {
            if (remoteVoicemail.isRead() && !localVoicemail.isRead()) {
                mQueryHelper.markReadInDatabase(localVoicemail);
            }
            if (!TextUtils.isEmpty(remoteVoicemail.getTranscription()) && TextUtils.isEmpty(localVoicemail.getTranscription())) {
                LoggerUtils.logImpressionOnMainThread(mContext, DialerImpression.Type.VVM_TRANSCRIPTION_DOWNLOADED);
                mQueryHelper.updateWithTranscription(localVoicemail, remoteVoicemail.getTranscription());
            }
        }
    }
    // The leftover messages are messages that exist on the server but not locally.
    boolean prefetchEnabled = shouldPerformPrefetch(account, imapHelper);
    for (Voicemail remoteVoicemail : remoteMap.values()) {
        if (!TextUtils.isEmpty(remoteVoicemail.getTranscription())) {
            LoggerUtils.logImpressionOnMainThread(mContext, DialerImpression.Type.VVM_TRANSCRIPTION_DOWNLOADED);
        }
        Uri uri = VoicemailDatabaseUtil.insert(mContext, remoteVoicemail);
        if (prefetchEnabled) {
            VoicemailFetchedCallback fetchedCallback = new VoicemailFetchedCallback(mContext, uri, account);
            imapHelper.fetchVoicemailPayload(fetchedCallback, remoteVoicemail.getSourceData());
        }
    }
    return true;
}
Also used : Voicemail(com.android.voicemail.impl.Voicemail) VoicemailFetchedCallback(com.android.voicemail.impl.fetch.VoicemailFetchedCallback) Uri(android.net.Uri)

Example 4 with Voicemail

use of com.android.voicemail.impl.Voicemail in project android_packages_apps_Dialer by LineageOS.

the class VoicemailsQueryHelper method getLocalVoicemails.

/**
 * Utility method to make queries to the voicemail database.
 *
 * <p>TODO(b/36588206) add PhoneAccountHandle filtering back
 *
 * @param selection A filter declaring which rows to return. {@code null} returns all rows.
 * @return A list of voicemails according to the selection statement.
 */
private List<Voicemail> getLocalVoicemails(@NonNull PhoneAccountHandle unusedPhoneAccountHandle, String selection) {
    Cursor cursor = mContentResolver.query(mSourceUri, PROJECTION, selection, null, null);
    if (cursor == null) {
        return null;
    }
    try {
        List<Voicemail> voicemails = new ArrayList<Voicemail>();
        while (cursor.moveToNext()) {
            final long id = cursor.getLong(_ID);
            final String sourceData = cursor.getString(SOURCE_DATA);
            final boolean isRead = cursor.getInt(IS_READ) == 1;
            final String transcription = cursor.getString(TRANSCRIPTION);
            Voicemail voicemail = Voicemail.createForUpdate(id, sourceData).setIsRead(isRead).setTranscription(transcription).build();
            voicemails.add(voicemail);
        }
        return voicemails;
    } finally {
        cursor.close();
    }
}
Also used : ArrayList(java.util.ArrayList) Voicemail(com.android.voicemail.impl.Voicemail) Cursor(android.database.Cursor)

Example 5 with Voicemail

use of com.android.voicemail.impl.Voicemail in project android_packages_apps_Dialer by LineageOS.

the class OmtpMessageReceiver method processSync.

/**
 * A sync message has two purposes: to signal a new voicemail message, and to indicate the
 * voicemails on the server have changed remotely (usually through the TUI). Save the new message
 * to the voicemail provider if it is the former case and perform a full sync in the latter case.
 *
 * @param message The sync message to extract data from.
 */
private void processSync(PhoneAccountHandle phone, SyncMessage message) {
    switch(message.getSyncTriggerEvent()) {
        case OmtpConstants.NEW_MESSAGE:
            if (!OmtpConstants.VOICE.equals(message.getContentType())) {
                VvmLog.i(TAG, "Non-voice message of type '" + message.getContentType() + "' received, ignoring");
                return;
            }
            Builder builder = Voicemail.createForInsertion(message.getTimestampMillis(), message.getSender()).setPhoneAccount(phone).setSourceData(message.getId()).setDuration(message.getLength()).setSourcePackage(mContext.getPackageName());
            Voicemail voicemail = builder.build();
            VoicemailsQueryHelper queryHelper = new VoicemailsQueryHelper(mContext);
            if (queryHelper.isVoicemailUnique(voicemail)) {
                Uri uri = VoicemailDatabaseUtil.insert(mContext, voicemail);
                voicemail = builder.setId(ContentUris.parseId(uri)).setUri(uri).build();
                SyncOneTask.start(mContext, phone, voicemail);
            }
            break;
        case OmtpConstants.MAILBOX_UPDATE:
            SyncTask.start(mContext, phone, OmtpVvmSyncService.SYNC_DOWNLOAD_ONLY);
            break;
        case OmtpConstants.GREETINGS_UPDATE:
            // Not implemented in V1
            break;
        default:
            VvmLog.e(TAG, "Unrecognized sync trigger event: " + message.getSyncTriggerEvent());
            break;
    }
}
Also used : VoicemailsQueryHelper(com.android.voicemail.impl.sync.VoicemailsQueryHelper) Builder(com.android.voicemail.impl.Voicemail.Builder) Voicemail(com.android.voicemail.impl.Voicemail) Uri(android.net.Uri)

Aggregations

Voicemail (com.android.voicemail.impl.Voicemail)6 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 Message (com.android.voicemail.impl.mail.Message)2 MimeMessage (com.android.voicemail.impl.mail.internet.MimeMessage)2 TargetApi (android.annotation.TargetApi)1 Builder (com.android.voicemail.impl.Voicemail.Builder)1 VoicemailFetchedCallback (com.android.voicemail.impl.fetch.VoicemailFetchedCallback)1 FetchProfile (com.android.voicemail.impl.mail.FetchProfile)1 MessagingException (com.android.voicemail.impl.mail.MessagingException)1 VoicemailsQueryHelper (com.android.voicemail.impl.sync.VoicemailsQueryHelper)1