summaryrefslogtreecommitdiff
path: root/java/com/android/voicemail/impl/ActivationTask.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/voicemail/impl/ActivationTask.java')
-rw-r--r--java/com/android/voicemail/impl/ActivationTask.java92
1 files changed, 31 insertions, 61 deletions
diff --git a/java/com/android/voicemail/impl/ActivationTask.java b/java/com/android/voicemail/impl/ActivationTask.java
index b0ad3bafc..6e27b5015 100644
--- a/java/com/android/voicemail/impl/ActivationTask.java
+++ b/java/com/android/voicemail/impl/ActivationTask.java
@@ -19,11 +19,9 @@ package com.android.voicemail.impl;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
-import android.database.ContentObserver;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.provider.Settings;
-import android.provider.Settings.Global;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.telecom.PhoneAccountHandle;
@@ -31,6 +29,7 @@ import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.proguard.UsedByReflection;
+import com.android.voicemail.VoicemailClient;
import com.android.voicemail.impl.protocol.VisualVoicemailProtocol;
import com.android.voicemail.impl.scheduling.BaseTask;
import com.android.voicemail.impl.scheduling.RetryPolicy;
@@ -42,8 +41,6 @@ import com.android.voicemail.impl.sync.SyncTask;
import com.android.voicemail.impl.sync.VvmAccountManager;
import com.android.voicemail.impl.utils.LoggerUtils;
import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
@@ -66,8 +63,6 @@ public class ActivationTask extends BaseTask {
private static final String EXTRA_MESSAGE_DATA_BUNDLE = "extra_message_data_bundle";
- @Nullable private static DeviceProvisionedObserver sDeviceProvisionedObserver;
-
private final RetryPolicy mRetryPolicy;
private Bundle mMessageData;
@@ -97,7 +92,7 @@ public class ActivationTask extends BaseTask {
// Activation might need information such as system language to be set, so wait until
// the setup wizard is finished. The data bundle from the SMS will be re-requested upon
// activation.
- queueActivationAfterProvisioned(context, phoneAccountHandle);
+ DeviceProvisionedJobService.activateAfterProvisioned(context, phoneAccountHandle);
return;
}
@@ -105,7 +100,7 @@ public class ActivationTask extends BaseTask {
if (messageData != null) {
intent.putExtra(EXTRA_MESSAGE_DATA_BUNDLE, messageData);
}
- context.startService(intent);
+ context.sendBroadcast(intent);
}
@Override
@@ -136,6 +131,8 @@ public class ActivationTask extends BaseTask {
return;
}
+ PreOMigrationHandler.migrate(getContext(), phoneAccountHandle);
+
if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "VVM is disabled");
return;
@@ -163,6 +160,7 @@ public class ActivationTask extends BaseTask {
if (VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Account is already activated");
+ onSuccess(getContext(), phoneAccountHandle);
return;
}
helper.handleEvent(
@@ -222,7 +220,7 @@ public class ActivationTask extends BaseTask {
+ message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.d(TAG, "subscriber ready, no activation required");
- updateSource(getContext(), phoneAccountHandle, status, message);
+ updateSource(getContext(), phoneAccountHandle, message);
} else {
if (helper.supportsProvisioning()) {
VvmLog.i(TAG, "Subscriber not ready, start provisioning");
@@ -232,7 +230,7 @@ public class ActivationTask extends BaseTask {
VvmLog.i(TAG, "Subscriber new but provisioning is not supported");
// Ignore the non-ready state and attempt to use the provided info as is.
// This is probably caused by not completing the new user tutorial.
- updateSource(getContext(), phoneAccountHandle, status, message);
+ updateSource(getContext(), phoneAccountHandle, message);
} else {
VvmLog.i(TAG, "Subscriber not ready but provisioning is not supported");
helper.handleEvent(status, OmtpEvents.CONFIG_SERVICE_NOT_AVAILABLE);
@@ -242,25 +240,38 @@ public class ActivationTask extends BaseTask {
getContext(), DialerImpression.Type.VVM_ACTIVATION_COMPLETED);
}
- public static void updateSource(
- Context context,
- PhoneAccountHandle phone,
- VoicemailStatus.Editor status,
- StatusMessage message) {
+ private static void updateSource(
+ Context context, PhoneAccountHandle phone, StatusMessage message) {
if (OmtpConstants.SUCCESS.equals(message.getReturnCode())) {
- OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(context, phone);
- helper.handleEvent(status, OmtpEvents.CONFIG_REQUEST_STATUS_SUCCESS);
-
// Save the IMAP credentials in preferences so they are persistent and can be retrieved.
VvmAccountManager.addAccount(context, phone, message);
-
- SyncTask.start(context, phone, OmtpVvmSyncService.SYNC_FULL_SYNC);
+ onSuccess(context, phone);
} else {
VvmLog.e(TAG, "Visual voicemail not available for subscriber.");
}
}
+ private static void onSuccess(Context context, PhoneAccountHandle phoneAccountHandle) {
+ OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(context, phoneAccountHandle);
+ helper.handleEvent(
+ VoicemailStatus.edit(context, phoneAccountHandle),
+ OmtpEvents.CONFIG_REQUEST_STATUS_SUCCESS);
+ clearLegacyVoicemailNotification(context, phoneAccountHandle);
+ SyncTask.start(context, phoneAccountHandle, OmtpVvmSyncService.SYNC_FULL_SYNC);
+ }
+
+ /** Sends a broadcast to the dialer UI to clear legacy voicemail notifications if any. */
+ private static void clearLegacyVoicemailNotification(
+ Context context, PhoneAccountHandle phoneAccountHandle) {
+ 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 zero will clear the notification.
+ intent.putExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, 0);
+ context.sendBroadcast(intent);
+ }
+
private static boolean hasSignal(Context context, PhoneAccountHandle phoneAccountHandle) {
TelephonyManager telephonyManager =
context
@@ -268,45 +279,4 @@ public class ActivationTask extends BaseTask {
.createForPhoneAccountHandle(phoneAccountHandle);
return telephonyManager.getServiceState().getState() == ServiceState.STATE_IN_SERVICE;
}
-
- private static void queueActivationAfterProvisioned(
- Context context, PhoneAccountHandle phoneAccountHandle) {
- if (sDeviceProvisionedObserver == null) {
- sDeviceProvisionedObserver = new DeviceProvisionedObserver(context);
- context
- .getContentResolver()
- .registerContentObserver(
- Settings.Global.getUriFor(Global.DEVICE_PROVISIONED),
- false,
- sDeviceProvisionedObserver);
- }
- sDeviceProvisionedObserver.addPhoneAcountHandle(phoneAccountHandle);
- }
-
- private static class DeviceProvisionedObserver extends ContentObserver {
-
- private final Context mContext;
- private final Set<PhoneAccountHandle> mPhoneAccountHandles = new HashSet<>();
-
- private DeviceProvisionedObserver(Context context) {
- super(null);
- mContext = context;
- }
-
- public void addPhoneAcountHandle(PhoneAccountHandle phoneAccountHandle) {
- mPhoneAccountHandles.add(phoneAccountHandle);
- }
-
- @Override
- public void onChange(boolean selfChange) {
- if (isDeviceProvisioned(mContext)) {
- VvmLog.i(TAG, "device provisioned, resuming activation");
- for (PhoneAccountHandle phoneAccountHandle : mPhoneAccountHandles) {
- start(mContext, phoneAccountHandle, null);
- }
- mContext.getContentResolver().unregisterContentObserver(sDeviceProvisionedObserver);
- sDeviceProvisionedObserver = null;
- }
- }
- }
}