From 8369df095a73a77b3715f8ae7ba06089cebca4ce Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Wed, 3 May 2017 10:27:13 -0700 Subject: This change reflects the Dialer V10 RC00 branch. RC00 is based on: branch: dialer-android_release_branch/153304843.1 synced to: 153304843 following the instructions at go/dialer-aosp-release. In this release: * Removes final apache sources. * Uses native lite compilation. More drops will follow with subsequent release candidates until we reach our final v10 release, in cadence with our prebuilt drops. Test: TreeHugger, on device Change-Id: Ic9684057230f9b579c777820c746cd21bf45ec0f --- .../voicemail/impl/sms/LegacyModeSmsHandler.java | 92 +++++++++++++++++++--- 1 file changed, 79 insertions(+), 13 deletions(-) (limited to 'java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java') diff --git a/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java b/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java index 1d1a639c5..5decf6376 100644 --- a/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java +++ b/java/com/android/voicemail/impl/sms/LegacyModeSmsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Google Inc. All Rights Reserved. + * Copyright (C) 2016 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. @@ -16,13 +16,21 @@ package com.android.voicemail.impl.sms; +import android.annotation.TargetApi; +import android.app.PendingIntent; import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build.VERSION_CODES; import android.os.Bundle; +import android.support.annotation.Nullable; +import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; +import android.telephony.TelephonyManager; import android.telephony.VisualVoicemailSms; +import com.android.voicemail.VoicemailClient; import com.android.voicemail.impl.OmtpConstants; import com.android.voicemail.impl.OmtpVvmCarrierConfigHelper; -import com.android.voicemail.impl.TelephonyManagerStub; import com.android.voicemail.impl.VvmLog; /** @@ -30,37 +38,95 @@ import com.android.voicemail.impl.VvmLog; * * @see OmtpVvmCarrierConfigHelper#isLegacyModeEnabled() */ +@TargetApi(VERSION_CODES.O) public class LegacyModeSmsHandler { private static final String TAG = "LegacyModeSmsHandler"; + private static final int CALL_VOICEMAIL_REQUEST_CODE = 1; + private static final int LAUNCH_VOICEMAIL_SETTINGS_REQUEST_CODE = 2; + public static void handle(Context context, VisualVoicemailSms sms) { - VvmLog.v(TAG, "processing VVM SMS on legacy mode"); + VvmLog.i(TAG, "processing VVM SMS on legacy mode"); String eventType = sms.getPrefix(); Bundle data = sms.getFields(); PhoneAccountHandle handle = sms.getPhoneAccountHandle(); if (eventType.equals(OmtpConstants.SYNC_SMS_PREFIX)) { SyncMessage message = new SyncMessage(data); - VvmLog.v( + VvmLog.i( TAG, "Received SYNC sms for " + handle + " with event " + message.getSyncTriggerEvent()); switch (message.getSyncTriggerEvent()) { case OmtpConstants.NEW_MESSAGE: case OmtpConstants.MAILBOX_UPDATE: - // The user has called into the voicemail and the new message count could - // change. - // For some carriers new message count could be set to 0 even if there are still - // unread messages, to clear the message waiting indicator. - VvmLog.v(TAG, "updating MWI"); - - // Setting voicemail message count to non-zero will show the telephony voicemail - // notification, and zero will clear it. - TelephonyManagerStub.showVoicemailNotification(message.getNewMessageCount()); + sendLegacyVoicemailNotification(context, handle, message.getNewMessageCount()); + break; default: break; } } } + + private static void sendLegacyVoicemailNotification( + Context context, PhoneAccountHandle phoneAccountHandle, int messageCount) { + // The user has called into the voicemail and the new message count could + // change. + // For some carriers new message count could be set to 0 even if there are still + // unread messages, to clear the message waiting indicator. + + VvmLog.i(TAG, "sending voicemail notification"); + Intent intent = new Intent(VoicemailClient.ACTION_SHOW_LEGACY_VOICEMAIL); + intent.setPackage(context.getPackageName()); + intent.putExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + // Setting voicemail message count to non-zero will show the telephony voicemail + // notification, and zero will clear it. + intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, messageCount); + + String voicemailNumber = getVoicemailNumber(context, phoneAccountHandle); + PendingIntent callVoicemailPendingIntent = null; + PendingIntent launchVoicemailSettingsPendingIntent = null; + + if (voicemailNumber != null) { + callVoicemailPendingIntent = + PendingIntent.getActivity( + context, + CALL_VOICEMAIL_REQUEST_CODE, + new Intent( + Intent.ACTION_CALL, Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null)), + PendingIntent.FLAG_UPDATE_CURRENT); + } else { + Intent launchVoicemailSettingsIntent = + new Intent(TelephonyManager.ACTION_CONFIGURE_VOICEMAIL); + launchVoicemailSettingsIntent.putExtra(TelephonyManager.EXTRA_HIDE_PUBLIC_SETTINGS, true); + + launchVoicemailSettingsPendingIntent = + PendingIntent.getActivity( + context, + LAUNCH_VOICEMAIL_SETTINGS_REQUEST_CODE, + launchVoicemailSettingsIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + } + + intent.putExtra(TelephonyManager.EXTRA_VOICEMAIL_NUMBER, voicemailNumber); + intent.putExtra(TelephonyManager.EXTRA_CALL_VOICEMAIL_INTENT, callVoicemailPendingIntent); + intent.putExtra( + TelephonyManager.EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT, + launchVoicemailSettingsPendingIntent); + + context.sendBroadcast(intent); + } + + @Nullable + private static String getVoicemailNumber(Context context, PhoneAccountHandle phoneAccountHandle) { + TelephonyManager telephonyManager = + context + .getSystemService(TelephonyManager.class) + .createForPhoneAccountHandle(phoneAccountHandle); + if (telephonyManager == null) { + return null; + } + return telephonyManager.getVoiceMailNumber(); + } } -- cgit v1.2.3