Search in sources :

Example 1 with VisualVoicemailProtocol

use of com.android.voicemail.impl.protocol.VisualVoicemailProtocol 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);
    if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) {
        VvmLog.i(TAG, "VVM is disabled");
        return;
    }
    OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(getContext(), phoneAccountHandle);
    if (!helper.isValid()) {
        VvmLog.i(TAG, "VVM not supported on phoneAccountHandle " + phoneAccountHandle);
        VvmAccountManager.removeAccount(getContext(), phoneAccountHandle);
        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 (VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) {
        VvmLog.i(TAG, "Account is already activated");
        onSuccess(getContext(), phoneAccountHandle);
        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 = mRetryPolicy.getVoicemailStatusEditor();
    VisualVoicemailProtocol protocol = helper.getProtocol();
    Bundle data;
    if (mMessageData != null) {
        // The content of STATUS SMS is provided to launch this task, no need to request it
        // again.
        data = mMessageData;
    } 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);
    } else {
        if (helper.supportsProvisioning()) {
            VvmLog.i(TAG, "Subscriber not ready, start provisioning");
            helper.startProvisioning(this, phoneAccountHandle, status, message, data);
        } 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);
        } 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);
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) StatusSmsFetcher(com.android.voicemail.impl.sms.StatusSmsFetcher) Bundle(android.os.Bundle) IOException(java.io.IOException) StatusMessage(com.android.voicemail.impl.sms.StatusMessage) CancellationException(java.util.concurrent.CancellationException) VisualVoicemailProtocol(com.android.voicemail.impl.protocol.VisualVoicemailProtocol) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) WorkerThread(android.support.annotation.WorkerThread)

Example 2 with VisualVoicemailProtocol

use of com.android.voicemail.impl.protocol.VisualVoicemailProtocol in project android_packages_apps_Dialer by LineageOS.

the class OmtpMessageReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;
    VisualVoicemailSms sms = intent.getExtras().getParcelable(OmtpService.EXTRA_VOICEMAIL_SMS);
    PhoneAccountHandle phone = sms.getPhoneAccountHandle();
    if (phone == null) {
        // This should never happen
        VvmLog.i(TAG, "Received message for null phone account");
        return;
    }
    if (!context.getSystemService(UserManager.class).isUserUnlocked()) {
        VvmLog.i(TAG, "Received message on locked device");
        // LegacyModeSmsHandler can handle new message notifications without storage access
        LegacyModeSmsHandler.handle(context, sms);
        // done.
        return;
    }
    OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(mContext, phone);
    if (!helper.isValid()) {
        VvmLog.e(TAG, "vvm config no longer valid");
        return;
    }
    if (!VisualVoicemailSettingsUtil.isEnabled(mContext, phone)) {
        if (helper.isLegacyModeEnabled()) {
            LegacyModeSmsHandler.handle(context, sms);
        } else {
            VvmLog.i(TAG, "Received vvm message for disabled vvm source.");
        }
        return;
    }
    String eventType = sms.getPrefix();
    Bundle data = sms.getFields();
    if (eventType == null || data == null) {
        VvmLog.e(TAG, "Unparsable VVM SMS received, ignoring");
        return;
    }
    if (eventType.equals(OmtpConstants.SYNC_SMS_PREFIX)) {
        SyncMessage message = new SyncMessage(data);
        VvmLog.v(TAG, "Received SYNC sms for " + phone + " with event " + message.getSyncTriggerEvent());
        processSync(phone, message);
    } else if (eventType.equals(OmtpConstants.STATUS_SMS_PREFIX)) {
        VvmLog.v(TAG, "Received Status sms for " + phone);
        // If the STATUS SMS is initiated by ActivationTask the TaskSchedulerService will reject
        // the follow request. Providing the data will also prevent ActivationTask from
        // requesting another STATUS SMS. The following task will only run if the carrier
        // spontaneous send a STATUS SMS, in that case, the VVM service should be reactivated.
        ActivationTask.start(context, phone, data);
    } else {
        VvmLog.w(TAG, "Unknown prefix: " + eventType);
        VisualVoicemailProtocol protocol = helper.getProtocol();
        if (protocol == null) {
            return;
        }
        Bundle statusData = helper.getProtocol().translateStatusSmsBundle(helper, eventType, data);
        if (statusData != null) {
            VvmLog.i(TAG, "Protocol recognized the SMS as STATUS, activating");
            ActivationTask.start(context, phone, data);
        }
    }
}
Also used : OmtpVvmCarrierConfigHelper(com.android.voicemail.impl.OmtpVvmCarrierConfigHelper) PhoneAccountHandle(android.telecom.PhoneAccountHandle) Bundle(android.os.Bundle) VisualVoicemailSms(android.telephony.VisualVoicemailSms) VisualVoicemailProtocol(com.android.voicemail.impl.protocol.VisualVoicemailProtocol)

Example 3 with VisualVoicemailProtocol

use of com.android.voicemail.impl.protocol.VisualVoicemailProtocol in project android_packages_apps_Dialer by LineageOS.

the class StatusSmsFetcher method onReceive.

@Override
@MainThread
public void onReceive(Context context, Intent intent) {
    Assert.isMainThread();
    if (ACTION_REQUEST_SENT_INTENT.equals(intent.getAction())) {
        int resultCode = getResultCode();
        if (resultCode == Activity.RESULT_OK) {
            VvmLog.d(TAG, "Request SMS successfully sent");
            return;
        }
        VvmLog.e(TAG, "Request SMS send failed: " + sentSmsResultToString(resultCode));
        mFuture.cancel(true);
        return;
    }
    VisualVoicemailSms sms = intent.getExtras().getParcelable(OmtpService.EXTRA_VOICEMAIL_SMS);
    if (!mPhoneAccountHandle.equals(sms.getPhoneAccountHandle())) {
        return;
    }
    String eventType = sms.getPrefix();
    if (eventType.equals(OmtpConstants.STATUS_SMS_PREFIX)) {
        mFuture.complete(sms.getFields());
        return;
    }
    if (eventType.equals(OmtpConstants.SYNC_SMS_PREFIX)) {
        return;
    }
    VvmLog.i(TAG, "VVM SMS with event " + eventType + " received, attempting to translate to STATUS SMS");
    OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(context, mPhoneAccountHandle);
    VisualVoicemailProtocol protocol = helper.getProtocol();
    if (protocol == null) {
        return;
    }
    Bundle translatedBundle = protocol.translateStatusSmsBundle(helper, eventType, sms.getFields());
    if (translatedBundle != null) {
        VvmLog.i(TAG, "Translated to STATUS SMS");
        mFuture.complete(translatedBundle);
    }
}
Also used : OmtpVvmCarrierConfigHelper(com.android.voicemail.impl.OmtpVvmCarrierConfigHelper) Bundle(android.os.Bundle) VisualVoicemailSms(android.telephony.VisualVoicemailSms) VisualVoicemailProtocol(com.android.voicemail.impl.protocol.VisualVoicemailProtocol) MainThread(android.support.annotation.MainThread)

Aggregations

Bundle (android.os.Bundle)3 VisualVoicemailProtocol (com.android.voicemail.impl.protocol.VisualVoicemailProtocol)3 PhoneAccountHandle (android.telecom.PhoneAccountHandle)2 VisualVoicemailSms (android.telephony.VisualVoicemailSms)2 OmtpVvmCarrierConfigHelper (com.android.voicemail.impl.OmtpVvmCarrierConfigHelper)2 MainThread (android.support.annotation.MainThread)1 WorkerThread (android.support.annotation.WorkerThread)1 StatusMessage (com.android.voicemail.impl.sms.StatusMessage)1 StatusSmsFetcher (com.android.voicemail.impl.sms.StatusSmsFetcher)1 IOException (java.io.IOException)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1