summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/voicemail')
-rw-r--r--java/com/android/voicemail/VoicemailClient.java42
-rw-r--r--java/com/android/voicemail/impl/VoicemailClientImpl.java56
-rw-r--r--java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java53
-rw-r--r--java/com/android/voicemail/impl/transcribe/TranscriptionService.java4
-rw-r--r--java/com/android/voicemail/stub/StubVoicemailClient.java14
5 files changed, 127 insertions, 42 deletions
diff --git a/java/com/android/voicemail/VoicemailClient.java b/java/com/android/voicemail/VoicemailClient.java
index 1ce7ef75a..5b382f1dc 100644
--- a/java/com/android/voicemail/VoicemailClient.java
+++ b/java/com/android/voicemail/VoicemailClient.java
@@ -30,35 +30,25 @@ import java.util.List;
public interface VoicemailClient {
/**
- * Whether the voicemail module is enabled (OS has support and not disabled by flags, etc.). This
- * does not mean the carrier has support or user has enabled the feature.
- */
- boolean isVoicemailModuleEnabled();
-
- /**
* Broadcast to tell the client to upload local database changes to the server. Since the dialer
* UI and the client are in the same package, the {@link
* android.content.Intent#ACTION_PROVIDER_CHANGED} will always be a self-change even if the UI is
* external to the client.
*/
String ACTION_UPLOAD = "com.android.voicemail.VoicemailClient.ACTION_UPLOAD";
-
/** Common key for passing {@link PhoneAccountHandle} in bundles. */
String PARAM_PHONE_ACCOUNT_HANDLE = "phone_account_handle";
-
/**
* Broadcast from the client to inform the app to show a legacy voicemail notification. This
* broadcast is same as {@link TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION}.
*/
String ACTION_SHOW_LEGACY_VOICEMAIL =
"com.android.voicemail.VoicemailClient.ACTION_SHOW_LEGACY_VOICEMAIL";
-
/**
* Boolean extra send with {@link #ACTION_SHOW_LEGACY_VOICEMAIL}, indicating that the notification
* is sent by legacy mode and should not be suppressed even when VVM is activated
*/
String EXTRA_IS_LEGACY_MODE = "is_legacy_mode";
-
/**
* Secret code to launch the voicemail config activity intended for OEMs and Carriers. {@code
* *#*#VVMCONFIG#*#*}
@@ -66,6 +56,12 @@ public interface VoicemailClient {
String VOICEMAIL_SECRET_CODE = "886266344";
/**
+ * Whether the voicemail module is enabled (OS has support and not disabled by flags, etc.). This
+ * does not mean the carrier has support or user has enabled the feature.
+ */
+ boolean isVoicemailModuleEnabled();
+
+ /**
* Whether visual voicemail is supported by the carrier for the {@code phoneAccountHandle}. This
* is purely based on the MCCMNC, and a single account might still be disabled by the carrier.
*/
@@ -123,17 +119,23 @@ public interface VoicemailClient {
/**
* @return if the voicemail transcription feature is available on the current device. This depends
- * on whether the server side flag is turned on for the feature, and if the OS meets the
- * requirement for this feature.
+ * on whether the server side flag is turned on for the feature, visual voicemail is activated
+ * and enabled and if the OS meets the requirement for this feature.
*/
- boolean isVoicemailTranscriptionAvailable(Context context);
+ boolean isVoicemailTranscriptionAvailable(Context context, PhoneAccountHandle account);
+
+ /** @return if the voicemail transcription setting has been enabled by the user. */
+ boolean isVoicemailTranscriptionEnabled(Context context, PhoneAccountHandle account);
/** @return if the voicemail donation feature is available. */
- boolean isVoicemailDonationAvailable(Context context);
+ boolean isVoicemailDonationAvailable(Context context, PhoneAccountHandle account);
/** @return if the voicemail donation setting has been enabled by the user. */
boolean isVoicemailDonationEnabled(Context context, PhoneAccountHandle account);
+ void setVoicemailTranscriptionEnabled(
+ Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled);
+
void setVoicemailDonationEnabled(
Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled);
@@ -162,12 +164,6 @@ public interface VoicemailClient {
@MainThread
void onShutdown(@NonNull Context context);
- /** Listener for changes in {@link #isActivated(Context, PhoneAccountHandle)} */
- interface ActivationStateListener {
- @MainThread
- void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated);
- }
-
@MainThread
void addActivationStateListener(ActivationStateListener listener);
@@ -187,4 +183,10 @@ public interface VoicemailClient {
*/
@Nullable
String getCarrierConfigString(Context context, PhoneAccountHandle phoneAccountHandle, String key);
+
+ /** Listener for changes in {@link #isActivated(Context, PhoneAccountHandle)} */
+ interface ActivationStateListener {
+ @MainThread
+ void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated);
+ }
}
diff --git a/java/com/android/voicemail/impl/VoicemailClientImpl.java b/java/com/android/voicemail/impl/VoicemailClientImpl.java
index 993594eb3..b0881c9a3 100644
--- a/java/com/android/voicemail/impl/VoicemailClientImpl.java
+++ b/java/com/android/voicemail/impl/VoicemailClientImpl.java
@@ -123,13 +123,28 @@ public class VoicemailClientImpl implements VoicemailClient {
}
@Override
- public boolean isVoicemailTranscriptionAvailable(Context context) {
+ public boolean isVoicemailTranscriptionAvailable(
+ Context context, PhoneAccountHandle phoneAccountHandle) {
if (!BuildCompat.isAtLeastO()) {
LogUtil.i(
"VoicemailClientImpl.isVoicemailTranscriptionAvailable", "not running on O or later");
return false;
}
+ if (!isVoicemailEnabled(context, phoneAccountHandle)) {
+ LogUtil.i(
+ "VoicemailClientImpl.isVoicemailTranscriptionAvailable",
+ "visual voicemail is not enabled");
+ return false;
+ }
+
+ if (!isActivated(context, phoneAccountHandle)) {
+ LogUtil.i(
+ "VoicemailClientImpl.isVoicemailTranscriptionAvailable",
+ "visual voicemail is not activated");
+ return false;
+ }
+
TranscriptionConfigProvider provider = new TranscriptionConfigProvider(context);
if (!provider.isVoicemailTranscriptionAvailable()) {
LogUtil.i(
@@ -141,12 +156,24 @@ public class VoicemailClientImpl implements VoicemailClient {
}
@Override
- public boolean isVoicemailDonationAvailable(Context context) {
- if (!isVoicemailTranscriptionAvailable(context)) {
+ public boolean isVoicemailTranscriptionEnabled(Context context, PhoneAccountHandle account) {
+ return isVoicemailTranscriptionAvailable(context, account)
+ && VisualVoicemailSettingsUtil.isVoicemailTranscriptionEnabled(context, account);
+ }
+
+ @Override
+ public boolean isVoicemailDonationAvailable(
+ Context context, PhoneAccountHandle phoneAccountHandle) {
+ if (!isVoicemailTranscriptionAvailable(context, phoneAccountHandle)) {
LogUtil.i("VoicemailClientImpl.isVoicemailDonationAvailable", "transcription not available");
return false;
}
+ if (!isVoicemailTranscriptionEnabled(context, phoneAccountHandle)) {
+ LogUtil.i("VoicemailClientImpl.isVoicemailDonationAvailable", "transcription not enabled");
+ return false;
+ }
+
TranscriptionConfigProvider provider = new TranscriptionConfigProvider(context);
if (!provider.isVoicemailDonationAvailable()) {
LogUtil.i("VoicemailClientImpl.isVoicemailDonationAvailable", "feature disabled by config");
@@ -158,13 +185,34 @@ public class VoicemailClientImpl implements VoicemailClient {
@Override
public boolean isVoicemailDonationEnabled(Context context, PhoneAccountHandle account) {
- return isVoicemailTranscriptionAvailable(context)
+ return isVoicemailTranscriptionEnabled(context, account)
+ && isVoicemailDonationAvailable(context, account)
&& VisualVoicemailSettingsUtil.isVoicemailDonationEnabled(context, account);
}
@Override
+ public void setVoicemailTranscriptionEnabled(
+ Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {
+ Assert.checkArgument(
+ isVoicemailTranscriptionAvailable(context, phoneAccountHandle),
+ "transcription must be available before enabling/disabling it");
+ VisualVoicemailSettingsUtil.setVoicemailTranscriptionEnabled(
+ context, phoneAccountHandle, enabled);
+ }
+
+ @Override
public void setVoicemailDonationEnabled(
Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {
+ if (enabled) {
+ Assert.checkArgument(
+ isVoicemailTranscriptionAvailable(context, phoneAccountHandle)
+ && isVoicemailTranscriptionEnabled(context, phoneAccountHandle),
+ "should not be able to enable donation without transcription "
+ + "available(value: %b) and enabled (value:%b) for account:%s",
+ isVoicemailTranscriptionAvailable(context, phoneAccountHandle),
+ isVoicemailTranscriptionEnabled(context, phoneAccountHandle),
+ phoneAccountHandle.toString());
+ }
VisualVoicemailSettingsUtil.setVoicemailDonationEnabled(context, phoneAccountHandle, enabled);
}
diff --git a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java
index e42d56938..3e006988e 100644
--- a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java
+++ b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java
@@ -33,6 +33,7 @@ public class VisualVoicemailSettingsUtil {
@VisibleForTesting public static final String IS_ENABLED_KEY = "is_enabled";
private static final String ARCHIVE_ENABLED_KEY = "archive_is_enabled";
+ private static final String TRANSCRIBE_VOICEMAILS_KEY = "transcribe_voicemails";
private static final String DONATE_VOICEMAILS_KEY = "donate_voicemails";
public static void setEnabled(
@@ -59,21 +60,6 @@ public class VisualVoicemailSettingsUtil {
}
}
- private static class VoicemailDeleteWorker implements Worker<Void, Void> {
- 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<Void, Void> {
+ 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;
}
@@ -86,6 +92,10 @@ public final class StubVoicemailClient implements VoicemailClient {
}
@Override
+ public void setVoicemailTranscriptionEnabled(
+ Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {}
+
+ @Override
public void setVoicemailDonationEnabled(
Context context, PhoneAccountHandle phoneAccountHandle, boolean enabled) {}