From cd3d49843431913c2ff042d2294a8b5201877882 Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 19 Mar 2018 15:20:59 -0700 Subject: Implement VoicemailDataSource This data source determines if the call is to the voicemail inbox. isVoicemail() is removed from NumberAttributes and PhoneLookup. It is yet decided how in call UI should handle voicemail calls in the future. TAG_CHANGE_OK=proto not in prod yet. Please clear app data. TYPE_CHANGE_OK=above Bug: 70989587 Test: Unit tests PiperOrigin-RevId: 189650273 Change-Id: Iafebf1abb18c74301b62a72d1d04deecd6d78d29 --- .../datasources/voicemail/VoicemailDataSource.java | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java (limited to 'java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java') diff --git a/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java b/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java new file mode 100644 index 000000000..e8dc3e1eb --- /dev/null +++ b/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2018 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.calllog.datasources.voicemail; + +import android.content.ContentValues; +import android.content.Context; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telephony.TelephonyManager; +import com.android.dialer.DialerPhoneNumber; +import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog; +import com.android.dialer.calllog.datasources.CallLogDataSource; +import com.android.dialer.calllog.datasources.CallLogMutations; +import com.android.dialer.calllog.datasources.util.RowCombiner; +import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; +import com.android.dialer.telecom.TelecomUtil; +import com.android.dialer.util.PermissionsUtil; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.protobuf.InvalidProtocolBufferException; +import java.util.List; +import java.util.Map.Entry; +import javax.inject.Inject; + +/** Provide information for whether the call is a call to the voicemail inbox. */ +public class VoicemailDataSource implements CallLogDataSource { + + private final ListeningExecutorService backgroundExecutor; + + @Inject + VoicemailDataSource(@BackgroundExecutor ListeningExecutorService backgroundExecutor) { + this.backgroundExecutor = backgroundExecutor; + } + + @Override + public ListenableFuture isDirty(Context appContext) { + // The isVoicemail status is immutable and permanent. The call will always show as "Voicemail" + // even if the SIM is swapped. Dialing the row will result in some unexpected number after a SIM + // swap but this is deemed acceptable. + return Futures.immediateFuture(false); + } + + @Override + @SuppressWarnings("missingPermission") + public ListenableFuture fill(Context appContext, CallLogMutations mutations) { + if (!PermissionsUtil.hasReadPhoneStatePermissions(appContext)) { + return Futures.immediateFuture(null); + } + return backgroundExecutor.submit( + () -> { + TelecomManager telecomManager = appContext.getSystemService(TelecomManager.class); + for (Entry insert : mutations.getInserts().entrySet()) { + ContentValues values = insert.getValue(); + PhoneAccountHandle phoneAccountHandle = + TelecomUtil.composePhoneAccountHandle( + values.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_COMPONENT_NAME), + values.getAsString(AnnotatedCallLog.PHONE_ACCOUNT_ID)); + DialerPhoneNumber dialerPhoneNumber; + try { + dialerPhoneNumber = + DialerPhoneNumber.parseFrom(values.getAsByteArray(AnnotatedCallLog.NUMBER)); + } catch (InvalidProtocolBufferException e) { + throw new IllegalStateException(e); + } + + if (telecomManager.isVoiceMailNumber( + phoneAccountHandle, dialerPhoneNumber.getNormalizedNumber())) { + values.put(AnnotatedCallLog.IS_VOICEMAIL_CALL, 1); + TelephonyManager telephonyManager = + TelephonyManagerCompat.getTelephonyManagerForPhoneAccountHandle( + appContext, phoneAccountHandle); + values.put( + AnnotatedCallLog.VOICEMAIL_CALL_TAG, telephonyManager.getVoiceMailAlphaTag()); + } + } + return null; + }); + } + + @Override + public ListenableFuture onSuccessfulFill(Context appContext) { + return Futures.immediateFuture(null); + } + + @Override + public ContentValues coalesce(List individualRowsSortedByTimestampDesc) { + return new RowCombiner(individualRowsSortedByTimestampDesc) + .useMostRecentInt(AnnotatedCallLog.IS_VOICEMAIL_CALL) + .useMostRecentString(AnnotatedCallLog.VOICEMAIL_CALL_TAG) + .combine(); + } + + @Override + public void registerContentObservers(Context appContext) {} +} -- cgit v1.2.3