Search in sources :

Example 1 with VisualVoicemailSms

use of android.telephony.VisualVoicemailSms in project robolectric by robolectric.

the class ShadowVisualVoicemailSmsTest method parcelable_unparcelable.

@Test
public void parcelable_unparcelable() {
    Bundle bundle = new Bundle();
    bundle.putString("key", "value");
    shadowSms.setPhoneAccountHandle(phoneAccountHandle).setPrefix("prefix").setFields(bundle).setMessageBody("messageBody");
    Parcel parcel = Parcel.obtain();
    sms.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    VisualVoicemailSms newSms = VisualVoicemailSms.CREATOR.createFromParcel(parcel);
    assertThat(newSms.getPhoneAccountHandle()).isEqualTo(phoneAccountHandle);
    assertThat(newSms.getPrefix()).isEqualTo("prefix");
    assertThat(newSms.getFields().getString("key")).isEqualTo("value");
    assertThat(newSms.getMessageBody()).isEqualTo("messageBody");
}
Also used : Bundle(android.os.Bundle) Parcel(android.os.Parcel) VisualVoicemailSms(android.telephony.VisualVoicemailSms) Test(org.junit.Test)

Example 2 with VisualVoicemailSms

use of android.telephony.VisualVoicemailSms in project android_packages_apps_Dialer by LineageOS.

the class OmtpMessageReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    this.context = 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;
    }
    if (!VvmAccountManager.isAccountActivated(context, phone)) {
        VvmLog.i(TAG, "Received message on non-activated account");
        LegacyModeSmsHandler.handle(context, sms);
        return;
    }
    OmtpVvmCarrierConfigHelper helper = new OmtpVvmCarrierConfigHelper(this.context, phone);
    if (!helper.isValid()) {
        VvmLog.e(TAG, "vvm config no longer valid");
        return;
    }
    if (!VisualVoicemailSettingsUtil.isEnabled(this.context, 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 VisualVoicemailSms

use of android.telephony.VisualVoicemailSms 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));
        future.cancel(true);
        return;
    }
    VisualVoicemailSms sms = intent.getExtras().getParcelable(OmtpService.EXTRA_VOICEMAIL_SMS);
    if (!phoneAccountHandle.equals(sms.getPhoneAccountHandle())) {
        return;
    }
    String eventType = sms.getPrefix();
    if (eventType.equals(OmtpConstants.STATUS_SMS_PREFIX)) {
        future.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, phoneAccountHandle);
    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");
        future.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 VisualVoicemailSms (android.telephony.VisualVoicemailSms)3 OmtpVvmCarrierConfigHelper (com.android.voicemail.impl.OmtpVvmCarrierConfigHelper)2 VisualVoicemailProtocol (com.android.voicemail.impl.protocol.VisualVoicemailProtocol)2 Parcel (android.os.Parcel)1 MainThread (android.support.annotation.MainThread)1 PhoneAccountHandle (android.telecom.PhoneAccountHandle)1 Test (org.junit.Test)1