From a7530f84656f1060957b14a4c946fd02cf88f7cd Mon Sep 17 00:00:00 2001 From: uabdullah Date: Fri, 16 Mar 2018 17:32:54 -0700 Subject: Refactor VM Settings and add support for voicemail transcription This CL refactors the existing voicemail settings fragment and adds UI support for voicemail transcription. It mainly deals with the following: - ensuring that when the VVM toggle is turned off, transcription and donations are gone. - when transcription is off, donation preference is gone. - donation is only available when transcription is available and enabled - as part of the refactor, fixes existing logging bugs - breaks preferences and its associated methods into helper methods when possible - groups relevant preferences together when possible Bug: 74033229 Test: Unit tests PiperOrigin-RevId: 189418217 Change-Id: I3442cb5752a235cfca643ba55df3fb75171e3fe4 --- .../dialer/app/calllog/PhoneCallDetailsHelper.java | 93 +++--- .../android/dialer/logging/dialer_impression.proto | 16 +- .../settings/VoicemailSettingsFragment.java | 311 ++++++++++++++------- .../voicemail/settings/res/values/strings.xml | 21 +- .../settings/res/xml/voicemail_settings.xml | 6 +- java/com/android/voicemail/VoicemailClient.java | 42 +-- .../voicemail/impl/VoicemailClientImpl.java | 56 +++- .../impl/settings/VisualVoicemailSettingsUtil.java | 53 ++-- .../impl/transcribe/TranscriptionService.java | 4 + .../voicemail/stub/StubVoicemailClient.java | 14 +- 10 files changed, 414 insertions(+), 202 deletions(-) diff --git a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java index 937f0419b..b88a959ed 100644 --- a/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java +++ b/java/com/android/dialer/app/calllog/PhoneCallDetailsHelper.java @@ -94,6 +94,49 @@ public class PhoneCallDetailsHelper calendar = Calendar.getInstance(); } + static boolean shouldShowVoicemailDonationPromo( + Context context, PhoneAccountHandle accountHandle) { + VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient(); + return client.isVoicemailDonationAvailable(context, accountHandle) + && !hasSeenVoicemailDonationPromo(context); + } + + static boolean hasSeenVoicemailDonationPromo(Context context) { + return StorageComponent.get(context.getApplicationContext()) + .unencryptedSharedPrefs() + .getBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, false); + } + + private static int dpsToPixels(Context context, int dps) { + return (int) + (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, dps, context.getResources().getDisplayMetrics())); + } + + private static void recordPromoShown(Context context) { + StorageComponent.get(context.getApplicationContext()) + .unencryptedSharedPrefs() + .edit() + .putBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, true) + .apply(); + } + + /** Returns true if primary name is empty or the data is from Cequint Caller ID. */ + private static boolean shouldShowLocation(PhoneCallDetails details) { + if (TextUtils.isEmpty(details.geocode)) { + return false; + } + // For caller ID provided by Cequint we want to show the geo location. + if (details.sourceType == ContactSource.Type.SOURCE_TYPE_CEQUINT_CALLER_ID) { + return true; + } + // Don't bother showing geo location for contacts. + if (!TextUtils.isEmpty(details.namePrimary)) { + return false; + } + return true; + } + /** Fills the call details views with content. */ public void setPhoneCallDetails(PhoneCallDetailsViews views, PhoneCallDetails details) { // Display up to a given number of icons. @@ -250,9 +293,10 @@ public class PhoneCallDetailsHelper return true; } - // Also show the rating option if voicemail transcription is available (but not enabled) + // Also show the rating option if voicemail donation is available (but not enabled) // and the donation promo has not yet been shown. - if (client.isVoicemailDonationAvailable(context) && !hasSeenVoicemailDonationPromo(context)) { + if (client.isVoicemailDonationAvailable(context, account) + && !hasSeenVoicemailDonationPromo(context)) { return true; } @@ -263,7 +307,7 @@ public class PhoneCallDetailsHelper TranscriptionRatingValue ratingValue, PhoneCallDetails details, View ratingView) { LogUtil.enterBlock("PhoneCallDetailsHelper.recordTranscriptionRating"); - if (shouldShowVoicemailDonationPromo(context)) { + if (shouldShowVoicemailDonationPromo(context, details.accountHandle)) { showVoicemailDonationPromo(ratingValue, details, ratingView); } else { TranscriptionRatingHelper.sendRating( @@ -275,19 +319,6 @@ public class PhoneCallDetailsHelper } } - static boolean shouldShowVoicemailDonationPromo(Context context) { - VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient(); - return client.isVoicemailTranscriptionAvailable(context) - && client.isVoicemailDonationAvailable(context) - && !hasSeenVoicemailDonationPromo(context); - } - - static boolean hasSeenVoicemailDonationPromo(Context context) { - return StorageComponent.get(context.getApplicationContext()) - .unencryptedSharedPrefs() - .getBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, false); - } - private void showVoicemailDonationPromo( TranscriptionRatingValue ratingValue, PhoneCallDetails details, View ratingView) { AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -360,20 +391,6 @@ public class PhoneCallDetailsHelper } } - private static int dpsToPixels(Context context, int dps) { - return (int) - (TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, dps, context.getResources().getDisplayMetrics())); - } - - private static void recordPromoShown(Context context) { - StorageComponent.get(context.getApplicationContext()) - .unencryptedSharedPrefs() - .edit() - .putBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, true) - .apply(); - } - private SpannableString getVoicemailDonationPromoContent() { return new ContentWithLearnMoreSpanner(context) .create( @@ -462,22 +479,6 @@ public class PhoneCallDetailsHelper return numberFormattedLabel; } - /** Returns true if primary name is empty or the data is from Cequint Caller ID. */ - private static boolean shouldShowLocation(PhoneCallDetails details) { - if (TextUtils.isEmpty(details.geocode)) { - return false; - } - // For caller ID provided by Cequint we want to show the geo location. - if (details.sourceType == ContactSource.Type.SOURCE_TYPE_CEQUINT_CALLER_ID) { - return true; - } - // Don't bother showing geo location for contacts. - if (!TextUtils.isEmpty(details.namePrimary)) { - return false; - } - return true; - } - public void setPhoneTypeLabelForTest(CharSequence phoneTypeLabel) { this.phoneTypeLabelForTest = phoneTypeLabel; } diff --git a/java/com/android/dialer/logging/dialer_impression.proto b/java/com/android/dialer/logging/dialer_impression.proto index c657768df..96ca9c6be 100644 --- a/java/com/android/dialer/logging/dialer_impression.proto +++ b/java/com/android/dialer/logging/dialer_impression.proto @@ -12,7 +12,7 @@ message DialerImpression { // Event enums to be used for Impression Logging in Dialer. // It's perfectly acceptable for this enum to be large // Values should be from 1000 to 100000. - // Next Tag: 1361 + // Next Tag: 1366 enum Type { UNKNOWN_AOSP_EVENT_TYPE = 1000; @@ -372,7 +372,7 @@ message DialerImpression { VVM_SETTINGS_VIEWED = 1148; VVM_CHANGE_PIN_CLICKED = 1149; VVM_CHANGE_PIN_COMPLETED = 1150; - VVM_CHANGE_RINGTONE_CLICKED = 1151; + VVM_CHANGE_RINGTONE_CLICKED = 1151 [deprecated = true]; VVM_CHANGE_VIBRATION_CLICKED = 1152; VVM_USER_ENABLED_IN_SETTINGS = 1153; VVM_USER_DISABLED_IN_SETTINGS = 1154; @@ -594,14 +594,12 @@ message DialerImpression { ASSISTED_DIALING_FEATURE_DISABLED_BY_USER = 1292; // User reports a same prefix call as spam from call history - REPORT_SAME_PREFIX_CALL_AS_SPAM_VIA_CALL_HISTORY = - 1290 + REPORT_SAME_PREFIX_CALL_AS_SPAM_VIA_CALL_HISTORY = 1290 ; // User reports a same prefix call as not spam from call history - REPORT_SAME_PREFIX_CALL_AS_NOT_SPAM_VIA_CALL_HISTORY = - 1291 + REPORT_SAME_PREFIX_CALL_AS_NOT_SPAM_VIA_CALL_HISTORY = 1291 ; @@ -715,5 +713,11 @@ message DialerImpression { SPAM_BLOCKING_DISABLED_THROUGH_SETTING = 1359; // Failure happened while modifying spam blocking setting. SPAM_BLOCKING_MODIFY_FAILURE_THROUGH_SETTING = 1360; + + VVM_NOTIFICATIONS_SETTING_CLICKED = 1361; + VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS = 1362; + VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS = 1363; + VVM_USER_TURNED_DONATION_ON_FROM_SETTINGS = 1364; + VVM_USER_TURNED_DONATION_OFF_FROM_SETTINGS = 1365; } } diff --git a/java/com/android/dialer/voicemail/settings/VoicemailSettingsFragment.java b/java/com/android/dialer/voicemail/settings/VoicemailSettingsFragment.java index 5ae26f5f7..b7db28e09 100644 --- a/java/com/android/dialer/voicemail/settings/VoicemailSettingsFragment.java +++ b/java/com/android/dialer/voicemail/settings/VoicemailSettingsFragment.java @@ -51,8 +51,6 @@ import com.google.common.base.Optional; public class VoicemailSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, ActivationStateListener { - private static final String TAG = "VmSettingsActivity"; - // Extras copied from com.android.phone.settings.VoicemailSettingsActivity, // it does not recognize EXTRA_PHONE_ACCOUNT_HANDLE in O. @VisibleForTesting @@ -63,21 +61,26 @@ public class VoicemailSettingsFragment extends PreferenceFragment static final String SUB_LABEL_EXTRA = "com.android.phone.settings.SubscriptionInfoHelper.SubscriptionLabel"; + private static final String TAG = "VmSettingsActivity"; @Nullable private PhoneAccountHandle phoneAccountHandle; private VoicemailClient voicemailClient; + // Settings that are independent of the carrier configurations private Preference voicemailNotificationPreference; - private SwitchPreference voicemailVisualVoicemail; - private SwitchPreference autoArchiveSwitchPreference; - private SwitchPreference donateVoicemailSwitchPreference; + private PreferenceScreen advancedSettingsPreference; + + // Settings that are supported by dialer only if the carrier configurations are valid. + private SwitchPreference visualVoicemailPreference; + private SwitchPreference voicemailAutoArchivePreference; + private SwitchPreference transcribeVoicemailPreference; + // Voicemail transcription analysis toggle + private SwitchPreference donateTranscribedVoicemailPreference; private Preference voicemailChangePinPreference; - private PreferenceScreen advancedSettings; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - phoneAccountHandle = Assert.isNotNull(getArguments().getParcelable(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE)); voicemailClient = VoicemailComponent.get(getContext()).getVoicemailClient(); @@ -95,92 +98,177 @@ public class VoicemailSettingsFragment extends PreferenceFragment addPreferencesFromResource(R.xml.voicemail_settings); - PreferenceScreen prefSet = getPreferenceScreen(); + initializePreferences(); - voicemailNotificationPreference = - findPreference(getString(R.string.voicemail_notifications_key)); - voicemailNotificationPreference.setIntent(getNotificationSettingsIntent()); + setupVisualVoicemailPreferences(); - voicemailNotificationPreference.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Logger.get(getContext()) - .logImpression(DialerImpression.Type.VVM_CHANGE_RINGTONE_CLICKED); - // Let the preference handle the click. - return false; - } - }); + setupNotificationsPreference(); + setupAdvancedSettingsPreference(); + } - voicemailVisualVoicemail = - (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_key)); + private void setupVisualVoicemailPreferences() { + if (!voicemailClient.hasCarrierSupport(getContext(), phoneAccountHandle)) { + removeAllVisualVoicemailPreferences(); + return; + } - autoArchiveSwitchPreference = - (SwitchPreference) - findPreference(getString(R.string.voicemail_visual_voicemail_archive_key)); + setupVisualVoicemailPreference(); - donateVoicemailSwitchPreference = - (SwitchPreference) - findPreference(getString(R.string.voicemail_visual_voicemail_donation_key)); + setupVisualVoicemailFeaturePreferences(); + setupVoicemailChangePinPreference(); + } + + private void setupVisualVoicemailFeaturePreferences() { + if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle) + || !voicemailClient.isActivated(getContext(), phoneAccountHandle)) { + removeAllTranscriptionPreferences(); + getPreferenceScreen().removePreference(voicemailAutoArchivePreference); + return; + } + setupAutoArchivePreference(); + updateTranscriptionPreferences(); + } + + private void updateTranscriptionPreferences() { if (!VoicemailComponent.get(getContext()) .getVoicemailClient() - .isVoicemailArchiveAvailable(getContext())) { - getPreferenceScreen().removePreference(autoArchiveSwitchPreference); + .isVoicemailTranscriptionAvailable(getContext(), phoneAccountHandle)) { + removeAllTranscriptionPreferences(); + return; + } else { + showTranscriptionEnabledPreference(); + updateTranscriptionDonationPreference(); } + } + private void showTranscriptionEnabledPreference() { + transcribeVoicemailPreference.setOnPreferenceChangeListener(this); + transcribeVoicemailPreference.setChecked( + voicemailClient.isVoicemailTranscriptionEnabled(getContext(), phoneAccountHandle)); + transcribeVoicemailPreference.setSummary( + R.string.voicemail_transcription_preference_summary_info); + transcribeVoicemailPreference.setEnabled(true); + getPreferenceScreen().addPreference(transcribeVoicemailPreference); + } + + private void updateTranscriptionDonationPreference() { if (!VoicemailComponent.get(getContext()) .getVoicemailClient() - .isVoicemailDonationAvailable(getContext())) { - getPreferenceScreen().removePreference(donateVoicemailSwitchPreference); + .isVoicemailDonationAvailable(getContext(), phoneAccountHandle)) { + getPreferenceScreen().removePreference(donateTranscribedVoicemailPreference); + } else { + showTranscriptionDonationEnabledPreferences(); } + } - voicemailChangePinPreference = findPreference(getString(R.string.voicemail_change_pin_key)); - - if (voicemailClient.hasCarrierSupport(getContext(), phoneAccountHandle)) { - Assert.isNotNull(phoneAccountHandle); - Intent changePinIntent = - new Intent(new Intent(getContext(), VoicemailChangePinActivity.class)); - changePinIntent.putExtra(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); - - voicemailChangePinPreference.setIntent(changePinIntent); - voicemailChangePinPreference.setOnPreferenceClickListener( - new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_CHANGE_PIN_CLICKED); - // Let the preference handle the click. - return false; - } - }); - if (VoicemailChangePinActivity.isPinScrambled(getContext(), phoneAccountHandle)) { - voicemailChangePinPreference.setTitle(R.string.voicemail_set_pin_preference_title); - } else { - voicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_preference_title); - } - updateChangePin(); + private void showTranscriptionDonationEnabledPreferences() { + donateTranscribedVoicemailPreference.setOnPreferenceChangeListener(this); + donateTranscribedVoicemailPreference.setChecked( + voicemailClient.isVoicemailDonationEnabled(getContext(), phoneAccountHandle)); + donateTranscribedVoicemailPreference.setSummary( + R.string.voicemail_donate_preference_summary_info); + donateTranscribedVoicemailPreference.setEnabled(true); + getPreferenceScreen().addPreference(donateTranscribedVoicemailPreference); + } - voicemailVisualVoicemail.setOnPreferenceChangeListener(this); - voicemailVisualVoicemail.setChecked( - voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)); + private void removeAllTranscriptionPreferences() { + getPreferenceScreen().removePreference(transcribeVoicemailPreference); + getPreferenceScreen().removePreference(donateTranscribedVoicemailPreference); + } - autoArchiveSwitchPreference.setOnPreferenceChangeListener(this); - autoArchiveSwitchPreference.setChecked( + private void setupAutoArchivePreference() { + if (!VoicemailComponent.get(getContext()) + .getVoicemailClient() + .isVoicemailArchiveAvailable(getContext())) { + getPreferenceScreen().removePreference(voicemailAutoArchivePreference); + } else { + voicemailAutoArchivePreference.setOnPreferenceChangeListener(this); + voicemailAutoArchivePreference.setChecked( voicemailClient.isVoicemailArchiveEnabled(getContext(), phoneAccountHandle)); + } + } - donateVoicemailSwitchPreference.setOnPreferenceChangeListener(this); - donateVoicemailSwitchPreference.setChecked( - voicemailClient.isVoicemailDonationEnabled(getContext(), phoneAccountHandle)); - updateDonateVoicemail(); + private void setupVisualVoicemailPreference() { + visualVoicemailPreference.setOnPreferenceChangeListener(this); + visualVoicemailPreference.setChecked( + voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)); + } + + private void initializePreferences() { + voicemailNotificationPreference = + findPreference(getString(R.string.voicemail_notifications_key)); + + advancedSettingsPreference = + (PreferenceScreen) findPreference(getString(R.string.voicemail_advanced_settings_key)); + + visualVoicemailPreference = + (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_key)); + + voicemailAutoArchivePreference = + (SwitchPreference) + findPreference(getString(R.string.voicemail_visual_voicemail_archive_key)); + + transcribeVoicemailPreference = + (SwitchPreference) + findPreference(getString(R.string.voicemail_visual_voicemail_transcription_key)); + + donateTranscribedVoicemailPreference = + (SwitchPreference) + findPreference(getString(R.string.voicemail_visual_voicemail_donation_key)); + + voicemailChangePinPreference = findPreference(getString(R.string.voicemail_change_pin_key)); + } + + /** Removes vvm settings since the carrier setup is not supported by Dialer */ + private void removeAllVisualVoicemailPreferences() { + PreferenceScreen prefSet = getPreferenceScreen(); + prefSet.removePreference(visualVoicemailPreference); + prefSet.removePreference(voicemailAutoArchivePreference); + prefSet.removePreference(transcribeVoicemailPreference); + prefSet.removePreference(donateTranscribedVoicemailPreference); + prefSet.removePreference(voicemailChangePinPreference); + } + + private void setupVoicemailChangePinPreference() { + Intent changePinIntent = new Intent(new Intent(getContext(), VoicemailChangePinActivity.class)); + changePinIntent.putExtra(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + + voicemailChangePinPreference.setIntent(changePinIntent); + voicemailChangePinPreference.setOnPreferenceClickListener( + new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_CHANGE_PIN_CLICKED); + // Let the preference handle the click. + return false; + } + }); + if (VoicemailChangePinActivity.isPinScrambled(getContext(), phoneAccountHandle)) { + voicemailChangePinPreference.setTitle(R.string.voicemail_set_pin_preference_title); } else { - prefSet.removePreference(voicemailVisualVoicemail); - prefSet.removePreference(autoArchiveSwitchPreference); - prefSet.removePreference(donateVoicemailSwitchPreference); - prefSet.removePreference(voicemailChangePinPreference); + voicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_preference_title); } + updateChangePinPreference(); + } - advancedSettings = - (PreferenceScreen) findPreference(getString(R.string.voicemail_advanced_settings_key)); + private void setupNotificationsPreference() { + + voicemailNotificationPreference.setIntent(getNotificationSettingsIntent()); + + voicemailNotificationPreference.setOnPreferenceClickListener( + new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Logger.get(getContext()) + .logImpression(DialerImpression.Type.VVM_NOTIFICATIONS_SETTING_CLICKED); + // Let the preference handle the click. + return false; + } + }); + } + + private void setupAdvancedSettingsPreference() { Intent advancedSettingsIntent = new Intent(TelephonyManager.ACTION_CONFIGURE_VOICEMAIL); advancedSettingsIntent.putExtra(TelephonyManager.EXTRA_HIDE_PUBLIC_SETTINGS, true); advancedSettingsIntent.putExtra( @@ -198,8 +286,9 @@ public class VoicemailSettingsFragment extends PreferenceFragment } } - advancedSettings.setIntent(advancedSettingsIntent); - voicemailChangePinPreference.setOnPreferenceClickListener( + advancedSettingsPreference.setIntent(advancedSettingsIntent); + + advancedSettingsPreference.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -226,7 +315,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment @Override public boolean onPreferenceChange(Preference preference, Object objValue) { LogUtil.d(TAG, "onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\""); - if (preference.getKey().equals(voicemailVisualVoicemail.getKey())) { + if (preference.getKey().equals(visualVoicemailPreference.getKey())) { boolean isEnabled = (boolean) objValue; if (!isEnabled) { showDisableConfirmationDialog(); @@ -235,12 +324,17 @@ public class VoicemailSettingsFragment extends PreferenceFragment } else { updateVoicemailEnabled(true); } - } else if (preference.getKey().equals(autoArchiveSwitchPreference.getKey())) { + } else if (preference.getKey().equals(voicemailAutoArchivePreference.getKey())) { logArchiveToggle((boolean) objValue); voicemailClient.setVoicemailArchiveEnabled( getContext(), phoneAccountHandle, (boolean) objValue); - } else if (preference.getKey().equals(donateVoicemailSwitchPreference.getKey())) { - logArchiveToggle((boolean) objValue); + } else if (preference.getKey().equals(transcribeVoicemailPreference.getKey())) { + logTranscribeToggle((boolean) objValue); + voicemailClient.setVoicemailTranscriptionEnabled( + getContext(), phoneAccountHandle, (boolean) objValue); + updateTranscriptionDonationPreference(); + } else if (preference.getKey().equals(donateTranscribedVoicemailPreference.getKey())) { + logDonationToggle((boolean) objValue); voicemailClient.setVoicemailDonationEnabled( getContext(), phoneAccountHandle, (boolean) objValue); } @@ -251,19 +345,19 @@ public class VoicemailSettingsFragment extends PreferenceFragment private void updateVoicemailEnabled(boolean isEnabled) { voicemailClient.setVoicemailEnabled(getContext(), phoneAccountHandle, isEnabled); - voicemailVisualVoicemail.setChecked(isEnabled); + visualVoicemailPreference.setChecked(isEnabled); if (isEnabled) { Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_ENABLED_IN_SETTINGS); } else { Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_DISABLED_IN_SETTINGS); } - - updateChangePin(); - updateDonateVoicemail(); + updateVoicemailSummaryMessage(); + updateTranscriptionPreferences(); + updateChangePinPreference(); } - private void updateChangePin() { + private void updateChangePinPreference() { if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)) { voicemailChangePinPreference.setSummary( R.string.voicemail_change_pin_preference_summary_disable); @@ -278,36 +372,55 @@ public class VoicemailSettingsFragment extends PreferenceFragment } } - private void updateDonateVoicemail() { - if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)) { - donateVoicemailSwitchPreference.setSummary( - R.string.voicemail_donate_preference_summary_disable); - donateVoicemailSwitchPreference.setEnabled(false); - } else if (!voicemailClient.isActivated(getContext(), phoneAccountHandle)) { - donateVoicemailSwitchPreference.setSummary( - R.string.voicemail_donate_preference_summary_not_activated); - donateVoicemailSwitchPreference.setEnabled(false); + private void logArchiveToggle(boolean userTurnedOn) { + if (userTurnedOn) { + Logger.get(getContext()) + .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_ON_FROM_SETTINGS); } else { - donateVoicemailSwitchPreference.setSummary(R.string.voicemail_donate_preference_summary_info); - donateVoicemailSwitchPreference.setEnabled(true); + Logger.get(getContext()) + .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_OFF_FROM_SETTINGS); } } - private void logArchiveToggle(boolean userTurnedOn) { + private void logTranscribeToggle(boolean userTurnedOn) { if (userTurnedOn) { Logger.get(getContext()) - .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_ON_FROM_SETTINGS); + .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS); } else { Logger.get(getContext()) - .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_OFF_FROM_SETTINGS); + .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS); + } + } + + private void logDonationToggle(boolean userTurnedOn) { + if (userTurnedOn) { + Logger.get(getContext()) + .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS); + } else { + Logger.get(getContext()) + .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS); } } @Override public void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated) { if (this.phoneAccountHandle.equals(phoneAccountHandle)) { - updateChangePin(); - updateDonateVoicemail(); + updateVoicemailSummaryMessage(); + updateTranscriptionPreferences(); + updateChangePinPreference(); + } + } + + /** + * Shows the activating message while visual voicemail is being activated. This is useful, since + * some toggles do not show up, until voicemail is activated e.g transcription and rating. + */ + private void updateVoicemailSummaryMessage() { + if (voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle) + && !voicemailClient.isActivated(getContext(), phoneAccountHandle)) { + visualVoicemailPreference.setSummary(R.string.voicemail_activating_summary_info); + } else { + visualVoicemailPreference.setSummary(""); } } diff --git a/java/com/android/dialer/voicemail/settings/res/values/strings.xml b/java/com/android/dialer/voicemail/settings/res/values/strings.xml index 1d2c104a3..db6309800 100644 --- a/java/com/android/dialer/voicemail/settings/res/values/strings.xml +++ b/java/com/android/dialer/voicemail/settings/res/values/strings.xml @@ -102,19 +102,24 @@ Unable to set PIN + transcribe_voicemails donate_voicemails + + + Voicemail transcription + Voicemail transcription analysis - - Visual voicemail must be enabled to donate voicemails - - Visual voicemail is not activated yet, please try again later + + Activating voicemail + + + Get transcripts of your voicemail using Google\'s transcription service Let Google review your voicemail messages to improve transcription accuracy @@ -125,7 +130,7 @@ TURN OFF - https://support.google.com/phoneapp/answer/2811844?hl=en%26ref_topic=7539039 - https://support.google.com/phoneapp/answer/2811844#voicemail_transcript + https://support.google.com/phoneapp/answer/2811844?hl=en%26ref_topic=7539039 + https://support.google.com/phoneapp/answer/2811844#voicemail_transcript diff --git a/java/com/android/dialer/voicemail/settings/res/xml/voicemail_settings.xml b/java/com/android/dialer/voicemail/settings/res/xml/voicemail_settings.xml index e558985a4..175a12740 100644 --- a/java/com/android/dialer/voicemail/settings/res/xml/voicemail_settings.xml +++ b/java/com/android/dialer/voicemail/settings/res/xml/voicemail_settings.xml @@ -30,9 +30,13 @@ android:dependency="@string/voicemail_visual_voicemail_key" android:title="@string/voicemail_visual_voicemail_auto_archive_switch_title"/>" + " " { - private final Context context; - - VoicemailDeleteWorker(Context context) { - this.context = context; - } - - @Override - public Void doInBackground(Void unused) { - int deleted = VoicemailDatabaseUtil.deleteAll(context); - VvmLog.i("VisualVoicemailSettingsUtil.doInBackground", "deleted " + deleted + " voicemails"); - return null; - } - } - private static void onSuccess(Void unused) { VvmLog.i("VisualVoicemailSettingsUtil.onSuccess", "delete voicemails"); } @@ -92,12 +78,24 @@ public class VisualVoicemailSettingsUtil { .apply(); } + public static void setVoicemailTranscriptionEnabled( + Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { + Assert.checkArgument( + VoicemailComponent.get(context) + .getVoicemailClient() + .isVoicemailTranscriptionAvailable(context, phoneAccount)); + new VisualVoicemailPreferences(context, phoneAccount) + .edit() + .putBoolean(TRANSCRIBE_VOICEMAILS_KEY, isEnabled) + .apply(); + } + public static void setVoicemailDonationEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { Assert.checkArgument( VoicemailComponent.get(context) .getVoicemailClient() - .isVoicemailTranscriptionAvailable(context)); + .isVoicemailTranscriptionAvailable(context, phoneAccount)); new VisualVoicemailPreferences(context, phoneAccount) .edit() .putBoolean(DONATE_VOICEMAILS_KEY, isEnabled) @@ -125,6 +123,14 @@ public class VisualVoicemailSettingsUtil { return prefs.getBoolean(ARCHIVE_ENABLED_KEY, false); } + public static boolean isVoicemailTranscriptionEnabled( + Context context, PhoneAccountHandle phoneAccount) { + Assert.isNotNull(phoneAccount); + + VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); + return prefs.getBoolean(TRANSCRIBE_VOICEMAILS_KEY, false); + } + public static boolean isVoicemailDonationEnabled( Context context, PhoneAccountHandle phoneAccount) { Assert.isNotNull(phoneAccount); @@ -146,4 +152,19 @@ public class VisualVoicemailSettingsUtil { VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); return prefs.contains(IS_ENABLED_KEY); } + + private static class VoicemailDeleteWorker implements Worker { + private final Context context; + + VoicemailDeleteWorker(Context context) { + this.context = context; + } + + @Override + public Void doInBackground(Void unused) { + int deleted = VoicemailDatabaseUtil.deleteAll(context); + VvmLog.i("VisualVoicemailSettingsUtil.doInBackground", "deleted " + deleted + " voicemails"); + return null; + } + } } diff --git a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java index c206c0818..781e3477d 100644 --- a/java/com/android/voicemail/impl/transcribe/TranscriptionService.java +++ b/java/com/android/voicemail/impl/transcribe/TranscriptionService.java @@ -98,6 +98,10 @@ public class TranscriptionService extends JobService { return false; } VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient(); + if (!client.isVoicemailTranscriptionEnabled(context, account)) { + LogUtil.i("TranscriptionService.canTranscribeVoicemail", "transcription is not enabled"); + return false; + } if (!client.hasAcceptedTos(context, account)) { LogUtil.i("TranscriptionService.canTranscribeVoicemail", "hasn't accepted TOS"); return false; diff --git a/java/com/android/voicemail/stub/StubVoicemailClient.java b/java/com/android/voicemail/stub/StubVoicemailClient.java index 2b02261c4..0a1d55351 100644 --- a/java/com/android/voicemail/stub/StubVoicemailClient.java +++ b/java/com/android/voicemail/stub/StubVoicemailClient.java @@ -71,12 +71,18 @@ public final class StubVoicemailClient implements VoicemailClient { Context context, PhoneAccountHandle phoneAccountHandle, boolean value) {} @Override - public boolean isVoicemailTranscriptionAvailable(Context context) { + public boolean isVoicemailTranscriptionAvailable( + Context context, PhoneAccountHandle phoneAccountHandle) { return false; } @Override - public boolean isVoicemailDonationAvailable(Context context) { + public boolean isVoicemailTranscriptionEnabled(Context context, PhoneAccountHandle account) { + return false; + } + + @Override + public boolean isVoicemailDonationAvailable(Context context, PhoneAccountHandle account) { return false; } @@ -85,6 +91,10 @@ public final class StubVoicemailClient implements VoicemailClient { return false; } + @Override + public void setVoicemailTranscriptionEnabled( + Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {} + @Override public void setVoicemailDonationEnabled( Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {} -- cgit v1.2.3