From 4deaebc5a988eb83440693721f1ab28b180d8779 Mon Sep 17 00:00:00 2001 From: uabdullah Date: Mon, 22 Jan 2018 18:19:07 -0800 Subject: Move legacy voicemail/error to nui voicemail/listui/error All packages relating to NUI voicemail should be under third_party/java_src/android_app/dialer/java/com/android/dialer/voicemail/listui. Since there is a chance that during NUI development the legacy third_party/java_src/android_app/dialer/java/com/android/dialer/app/voicemail/error might undergo changes, it makes sense to move this package to the nui, so that no changes in the legacy code are missed for nui. This refactoring would also allow us to ensure that the strings do not need to be translated and that most of the code can be re-used for nui by hooking up the fragment and adapter to voicemail/listui/error. Bug: 71700117 Test: Unit tests PiperOrigin-RevId: 182868896 Change-Id: I23329654df5ce2bf612101708ed001ca308ae1ac --- .../error/VoicemailStatusCorruptionHandler.java | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 java/com/android/dialer/voicemail/listui/error/VoicemailStatusCorruptionHandler.java (limited to 'java/com/android/dialer/voicemail/listui/error/VoicemailStatusCorruptionHandler.java') diff --git a/java/com/android/dialer/voicemail/listui/error/VoicemailStatusCorruptionHandler.java b/java/com/android/dialer/voicemail/listui/error/VoicemailStatusCorruptionHandler.java new file mode 100644 index 000000000..630a17d8f --- /dev/null +++ b/java/com/android/dialer/voicemail/listui/error/VoicemailStatusCorruptionHandler.java @@ -0,0 +1,114 @@ +/* + * 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. + * 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.voicemail.listui.error; + +import android.content.ComponentName; +import android.content.Context; +import android.database.Cursor; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.provider.VoicemailContract.Status; +import android.telecom.PhoneAccountHandle; +import android.telephony.TelephonyManager; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; +import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; + +/** + * This class will detect the corruption in the voicemail status and log it so we can track how many + * users are affected. + */ +public class VoicemailStatusCorruptionHandler { + + /** Where the check is made so logging can be done. */ + public enum Source { + Activity, + Notification + } + + private static final String CONFIG_VVM_STATUS_FIX_DISABLED = "vvm_status_fix_disabled"; + + public static void maybeFixVoicemailStatus(Context context, Cursor statusCursor, Source source) { + + if (ConfigProviderBindings.get(context).getBoolean(CONFIG_VVM_STATUS_FIX_DISABLED, false)) { + return; + } + + if (VERSION.SDK_INT != VERSION_CODES.N_MR1) { + // This issue is specific to N MR1, it is fixed in future SDK. + return; + } + + if (statusCursor.getCount() == 0) { + return; + } + + statusCursor.moveToFirst(); + VoicemailStatus status = new VoicemailStatus(context, statusCursor); + PhoneAccountHandle phoneAccountHandle = + new PhoneAccountHandle( + ComponentName.unflattenFromString(status.phoneAccountComponentName), + status.phoneAccountId); + + TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); + + boolean visualVoicemailEnabled = + TelephonyManagerCompat.isVisualVoicemailEnabled(telephonyManager, phoneAccountHandle); + LogUtil.i( + "VoicemailStatusCorruptionHandler.maybeFixVoicemailStatus", + "Source=" + + source + + ", CONFIGURATION_STATE=" + + status.configurationState + + ", visualVoicemailEnabled=" + + visualVoicemailEnabled); + + // If visual voicemail is enabled, the CONFIGURATION_STATE should be either OK, PIN_NOT_SET, + // or other failure code. CONFIGURATION_STATE_NOT_CONFIGURED means that the client has been + // shut down improperly (a bug). The client should be reset or the VVM tab will be + // missing. + if (Status.CONFIGURATION_STATE_NOT_CONFIGURED == status.configurationState + && visualVoicemailEnabled) { + LogUtil.e( + "VoicemailStatusCorruptionHandler.maybeFixVoicemailStatus", + "VVM3 voicemail status corrupted"); + + switch (source) { + case Activity: + Logger.get(context) + .logImpression( + DialerImpression.Type + .VOICEMAIL_CONFIGURATION_STATE_CORRUPTION_DETECTED_FROM_ACTIVITY); + break; + case Notification: + Logger.get(context) + .logImpression( + DialerImpression.Type + .VOICEMAIL_CONFIGURATION_STATE_CORRUPTION_DETECTED_FROM_NOTIFICATION); + break; + default: + Assert.fail("this should never happen"); + break; + } + // At this point we could attempt to work around the issue by disabling and re-enabling + // voicemail. Unfortunately this work around is buggy so we'll do nothing for now. + } + } +} -- cgit v1.2.3