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");
}
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);
}
}
}
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);
}
}
Aggregations