use of com.android.voicemail.impl.sms.StatusMessage in project android_packages_apps_Dialer by LineageOS.
the class ActivationTask method onExecuteInBackgroundThread.
@Override
@WorkerThread
public void onExecuteInBackgroundThread() {
Assert.isNotMainThread();
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_STARTED);
PhoneAccountHandle phoneAccountHandle = getPhoneAccountHandle();
if (phoneAccountHandle == null) {
// This should never happen
VvmLog.e(TAG, "null PhoneAccountHandle");
return;
}
PreOMigrationHandler.migrate(getContext(), phoneAccountHandle);
OmtpVvmCarrierConfigHelper helper;
if (configForTest != null) {
helper = configForTest;
} else {
helper = new OmtpVvmCarrierConfigHelper(getContext(), phoneAccountHandle);
}
if (!helper.isValid()) {
VvmLog.i(TAG, "VVM not supported on phoneAccountHandle " + phoneAccountHandle);
VvmAccountManager.removeAccount(getContext(), phoneAccountHandle);
return;
}
if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) {
if (helper.isLegacyModeEnabled()) {
VvmLog.i(TAG, "Setting up filter for legacy mode");
helper.activateSmsFilter();
}
VvmLog.i(TAG, "VVM is disabled");
return;
}
// a good chance of being started up.
if (!VoicemailStatus.edit(getContext(), phoneAccountHandle).setType(helper.getVvmType()).apply()) {
VvmLog.e(TAG, "Failed to configure content provider - " + helper.getVvmType());
fail();
}
VvmLog.i(TAG, "VVM content provider configured - " + helper.getVvmType());
if (messageData == null && VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Account is already activated");
// The activated state might come from restored data, the filter still needs to be set up.
helper.activateSmsFilter();
onSuccess(getContext(), phoneAccountHandle, helper);
return;
}
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.CONFIG_ACTIVATING);
if (!hasSignal(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Service lost during activation, aborting");
// Restore the "NO SIGNAL" state since it will be overwritten by the CONFIG_ACTIVATING
// event.
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.NOTIFICATION_SERVICE_LOST);
// Don't retry, a new activation will be started after the signal returned.
return;
}
helper.activateSmsFilter();
VoicemailStatus.Editor status = retryPolicy.getVoicemailStatusEditor();
VisualVoicemailProtocol protocol = helper.getProtocol();
Bundle data;
boolean isCarrierInitiated = messageData != null;
if (isCarrierInitiated) {
// The content of STATUS SMS is provided to launch this task, no need to request it
// again.
data = messageData;
} else {
try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), phoneAccountHandle)) {
protocol.startActivation(helper, fetcher.getSentIntent());
// Both the fetcher and OmtpMessageReceiver will be triggered, but
// OmtpMessageReceiver will just route the SMS back to ActivationTask, which will be
// rejected because the task is still running.
data = fetcher.get();
} catch (TimeoutException e) {
// The carrier is expected to return an STATUS SMS within STATUS_SMS_TIMEOUT_MILLIS
// handleEvent() will do the logging.
helper.handleEvent(status, OmtpEvents.CONFIG_STATUS_SMS_TIME_OUT);
fail();
return;
} catch (CancellationException e) {
VvmLog.e(TAG, "Unable to send status request SMS");
fail();
return;
} catch (InterruptedException | ExecutionException | IOException e) {
VvmLog.e(TAG, "can't get future STATUS SMS", e);
fail();
return;
}
}
StatusMessage message = new StatusMessage(data);
VvmLog.d(TAG, "STATUS SMS received: st=" + message.getProvisioningStatus() + ", rc=" + message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.d(TAG, "subscriber ready, no activation required");
updateSource(getContext(), phoneAccountHandle, message, helper);
} else {
if (helper.supportsProvisioning()) {
VvmLog.i(TAG, "Subscriber not ready, start provisioning");
helper.startProvisioning(this, phoneAccountHandle, status, message, data, isCarrierInitiated);
} else if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_NEW)) {
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, message, helper);
} else {
VvmLog.i(TAG, "Subscriber not ready but provisioning is not supported");
helper.handleEvent(status, OmtpEvents.CONFIG_SERVICE_NOT_AVAILABLE);
}
}
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_COMPLETED);
}
use of com.android.voicemail.impl.sms.StatusMessage in project android_packages_apps_Dialer by LineageOS.
the class StatusCheckTask method onExecuteInBackgroundThread.
@Override
public void onExecuteInBackgroundThread() {
TelephonyManager telephonyManager = getContext().getSystemService(TelephonyManager.class).createForPhoneAccountHandle(getPhoneAccountHandle());
if (telephonyManager == null) {
VvmLog.w("StatusCheckTask.onExecuteInBackgroundThread", getPhoneAccountHandle() + " no longer valid");
return;
}
if (telephonyManager.getServiceState().getState() != ServiceState.STATE_IN_SERVICE) {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", getPhoneAccountHandle() + " not in service");
return;
}
OmtpVvmCarrierConfigHelper config = new OmtpVvmCarrierConfigHelper(getContext(), getPhoneAccountHandle());
if (!config.isValid()) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "config no longer valid for " + getPhoneAccountHandle());
VvmAccountManager.removeAccount(getContext(), getPhoneAccountHandle());
return;
}
Bundle data;
try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), getPhoneAccountHandle())) {
config.getProtocol().requestStatus(config, fetcher.getSentIntent());
// Both the fetcher and OmtpMessageReceiver will be triggered, but
// OmtpMessageReceiver will just route the SMS back to ActivationTask, which will be
// rejected because the task is still running.
data = fetcher.get();
} catch (TimeoutException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "timeout requesting status");
return;
} catch (CancellationException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "Unable to send status request SMS");
return;
} catch (InterruptedException | ExecutionException | IOException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "can't get future STATUS SMS", e);
return;
}
StatusMessage message = new StatusMessage(data);
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "STATUS SMS received: st=" + message.getProvisioningStatus() + ", rc=" + message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "subscriber ready, no activation required");
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_STATUS_CHECK_READY);
VvmAccountManager.addAccount(getContext(), getPhoneAccountHandle(), message);
} else {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "subscriber not ready, attempting reactivation");
VvmAccountManager.removeAccount(getContext(), getPhoneAccountHandle());
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_STATUS_CHECK_REACTIVATION);
ActivationTask.start(getContext(), getPhoneAccountHandle(), data);
}
}
use of com.android.voicemail.impl.sms.StatusMessage in project android_packages_apps_Dialer by MoKee.
the class StatusCheckTask method onExecuteInBackgroundThread.
@Override
public void onExecuteInBackgroundThread() {
TelephonyManager telephonyManager = getContext().getSystemService(TelephonyManager.class).createForPhoneAccountHandle(getPhoneAccountHandle());
if (telephonyManager == null) {
VvmLog.w("StatusCheckTask.onExecuteInBackgroundThread", getPhoneAccountHandle() + " no longer valid");
return;
}
if (telephonyManager.getServiceState().getState() != ServiceState.STATE_IN_SERVICE) {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", getPhoneAccountHandle() + " not in service");
return;
}
OmtpVvmCarrierConfigHelper config = new OmtpVvmCarrierConfigHelper(getContext(), getPhoneAccountHandle());
if (!config.isValid()) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "config no longer valid for " + getPhoneAccountHandle());
VvmAccountManager.removeAccount(getContext(), getPhoneAccountHandle());
return;
}
Bundle data;
try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), getPhoneAccountHandle())) {
config.getProtocol().requestStatus(config, fetcher.getSentIntent());
// Both the fetcher and OmtpMessageReceiver will be triggered, but
// OmtpMessageReceiver will just route the SMS back to ActivationTask, which will be
// rejected because the task is still running.
data = fetcher.get();
} catch (TimeoutException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "timeout requesting status");
return;
} catch (CancellationException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "Unable to send status request SMS");
return;
} catch (InterruptedException | ExecutionException | IOException e) {
VvmLog.e("StatusCheckTask.onExecuteInBackgroundThread", "can't get future STATUS SMS", e);
return;
}
StatusMessage message = new StatusMessage(data);
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "STATUS SMS received: st=" + message.getProvisioningStatus() + ", rc=" + message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "subscriber ready, no activation required");
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_STATUS_CHECK_READY);
VvmAccountManager.addAccount(getContext(), getPhoneAccountHandle(), message);
} else {
VvmLog.i("StatusCheckTask.onExecuteInBackgroundThread", "subscriber not ready, attempting reactivation");
VvmAccountManager.removeAccount(getContext(), getPhoneAccountHandle());
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_STATUS_CHECK_REACTIVATION);
ActivationTask.start(getContext(), getPhoneAccountHandle(), data);
}
}
use of com.android.voicemail.impl.sms.StatusMessage in project android_packages_apps_Dialer by MoKee.
the class ActivationTask method onExecuteInBackgroundThread.
@Override
@WorkerThread
public void onExecuteInBackgroundThread() {
Assert.isNotMainThread();
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_STARTED);
PhoneAccountHandle phoneAccountHandle = getPhoneAccountHandle();
if (phoneAccountHandle == null) {
// This should never happen
VvmLog.e(TAG, "null PhoneAccountHandle");
return;
}
PreOMigrationHandler.migrate(getContext(), phoneAccountHandle);
OmtpVvmCarrierConfigHelper helper;
if (configForTest != null) {
helper = configForTest;
} else {
helper = new OmtpVvmCarrierConfigHelper(getContext(), phoneAccountHandle);
}
if (!helper.isValid()) {
VvmLog.i(TAG, "VVM not supported on phoneAccountHandle " + phoneAccountHandle);
VvmAccountManager.removeAccount(getContext(), phoneAccountHandle);
return;
}
if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) {
if (helper.isLegacyModeEnabled()) {
VvmLog.i(TAG, "Setting up filter for legacy mode");
helper.activateSmsFilter();
}
VvmLog.i(TAG, "VVM is disabled");
return;
}
// a good chance of being started up.
if (!VoicemailStatus.edit(getContext(), phoneAccountHandle).setType(helper.getVvmType()).apply()) {
VvmLog.e(TAG, "Failed to configure content provider - " + helper.getVvmType());
fail();
}
VvmLog.i(TAG, "VVM content provider configured - " + helper.getVvmType());
if (messageData == null && VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Account is already activated");
// The activated state might come from restored data, the filter still needs to be set up.
helper.activateSmsFilter();
onSuccess(getContext(), phoneAccountHandle, helper);
return;
}
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.CONFIG_ACTIVATING);
if (!hasSignal(getContext(), phoneAccountHandle)) {
VvmLog.i(TAG, "Service lost during activation, aborting");
// Restore the "NO SIGNAL" state since it will be overwritten by the CONFIG_ACTIVATING
// event.
helper.handleEvent(VoicemailStatus.edit(getContext(), phoneAccountHandle), OmtpEvents.NOTIFICATION_SERVICE_LOST);
// Don't retry, a new activation will be started after the signal returned.
return;
}
helper.activateSmsFilter();
VoicemailStatus.Editor status = retryPolicy.getVoicemailStatusEditor();
VisualVoicemailProtocol protocol = helper.getProtocol();
Bundle data;
boolean isCarrierInitiated = messageData != null;
if (isCarrierInitiated) {
// The content of STATUS SMS is provided to launch this task, no need to request it
// again.
data = messageData;
} else {
try (StatusSmsFetcher fetcher = new StatusSmsFetcher(getContext(), phoneAccountHandle)) {
protocol.startActivation(helper, fetcher.getSentIntent());
// Both the fetcher and OmtpMessageReceiver will be triggered, but
// OmtpMessageReceiver will just route the SMS back to ActivationTask, which will be
// rejected because the task is still running.
data = fetcher.get();
} catch (TimeoutException e) {
// The carrier is expected to return an STATUS SMS within STATUS_SMS_TIMEOUT_MILLIS
// handleEvent() will do the logging.
helper.handleEvent(status, OmtpEvents.CONFIG_STATUS_SMS_TIME_OUT);
fail();
return;
} catch (CancellationException e) {
VvmLog.e(TAG, "Unable to send status request SMS");
fail();
return;
} catch (InterruptedException | ExecutionException | IOException e) {
VvmLog.e(TAG, "can't get future STATUS SMS", e);
fail();
return;
}
}
StatusMessage message = new StatusMessage(data);
VvmLog.d(TAG, "STATUS SMS received: st=" + message.getProvisioningStatus() + ", rc=" + message.getReturnCode());
if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_READY)) {
VvmLog.d(TAG, "subscriber ready, no activation required");
updateSource(getContext(), phoneAccountHandle, message, helper);
} else {
if (helper.supportsProvisioning()) {
VvmLog.i(TAG, "Subscriber not ready, start provisioning");
helper.startProvisioning(this, phoneAccountHandle, status, message, data, isCarrierInitiated);
} else if (message.getProvisioningStatus().equals(OmtpConstants.SUBSCRIBER_NEW)) {
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, message, helper);
} else {
VvmLog.i(TAG, "Subscriber not ready but provisioning is not supported");
helper.handleEvent(status, OmtpEvents.CONFIG_SERVICE_NOT_AVAILABLE);
}
}
LoggerUtils.logImpressionOnMainThread(getContext(), DialerImpression.Type.VVM_ACTIVATION_COMPLETED);
}
Aggregations