diff options
author | wangqi <wangqi@google.com> | 2017-06-29 13:14:51 -0700 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2017-07-06 14:26:50 -0700 |
commit | 69674662dbcf4b88fc4f2b290bd3ab925ae411c8 (patch) | |
tree | 5fad58b25e18f6fee78d0bb9315b9fb49156f6de /java/com/android/incallui/disconnectdialog | |
parent | fca382768e43a66dd5f723c2aba02fcc066c1ca5 (diff) |
Add video call not available dialog.
When telecom disconnect the video call with the code of DisconnectCause.ERROR and the DisconnectCause#getReason() of "IMS_ACCESS_BLOCKED", we should show an error dialog to user indicating that video call is not available and providing a option to make a voice call instead.
Screenshots:
https://screenshot.googleplex.com/YTUGVouoLmj
Bug: 33821263
Test: manual, VideoCallNotAvailablePromptTest
PiperOrigin-RevId: 160563754
Change-Id: Ie2eb735a92c577b5ae5a5e8b7efa2d699fc964bc
Diffstat (limited to 'java/com/android/incallui/disconnectdialog')
7 files changed, 351 insertions, 0 deletions
diff --git a/java/com/android/incallui/disconnectdialog/AndroidManifest.xml b/java/com/android/incallui/disconnectdialog/AndroidManifest.xml new file mode 100644 index 000000000..eec9807d8 --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/AndroidManifest.xml @@ -0,0 +1,19 @@ +<!-- + ~ Copyright (C) 2017 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<manifest + package="com.android.incallui.disconnectdialog"> +</manifest> diff --git a/java/com/android/incallui/disconnectdialog/DefaultErrorDialog.java b/java/com/android/incallui/disconnectdialog/DefaultErrorDialog.java new file mode 100644 index 000000000..2ce238718 --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/DefaultErrorDialog.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui.disconnectdialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.support.annotation.NonNull; +import android.telecom.DisconnectCause; +import android.text.TextUtils; +import android.util.Pair; +import com.android.incallui.call.DialerCall; + +/** Default error dialog shown to user after disconnect. */ +public class DefaultErrorDialog implements DisconnectDialog { + + @Override + public boolean shouldShow(DisconnectCause disconnectCause) { + return !TextUtils.isEmpty(disconnectCause.getDescription()) + && (disconnectCause.getCode() == DisconnectCause.ERROR + || disconnectCause.getCode() == DisconnectCause.RESTRICTED); + } + + @Override + public Pair<Dialog, CharSequence> createDialog(@NonNull Context context, DialerCall call) { + DisconnectCause disconnectCause = call.getDisconnectCause(); + CharSequence message = disconnectCause.getDescription(); + + Dialog dialog = + new AlertDialog.Builder(context) + .setMessage(message) + .setPositiveButton(android.R.string.cancel, null) + .create(); + return new Pair<>(dialog, message); + } +} diff --git a/java/com/android/incallui/disconnectdialog/DisconnectDialog.java b/java/com/android/incallui/disconnectdialog/DisconnectDialog.java new file mode 100644 index 000000000..0b2b8cc8f --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/DisconnectDialog.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui.disconnectdialog; + +import android.app.Dialog; +import android.content.Context; +import android.support.annotation.NonNull; +import android.telecom.DisconnectCause; +import android.util.Pair; +import com.android.incallui.call.DialerCall; + +/** Interface for disconnect dialog. */ +public interface DisconnectDialog { + + boolean shouldShow(DisconnectCause disconnectCause); + + Pair<Dialog, CharSequence> createDialog(@NonNull Context context, DialerCall call); +} diff --git a/java/com/android/incallui/disconnectdialog/DisconnectMessage.java b/java/com/android/incallui/disconnectdialog/DisconnectMessage.java new file mode 100644 index 000000000..97d58f27c --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/DisconnectMessage.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.incallui.disconnectdialog; + +import android.app.Dialog; +import android.content.Context; +import android.telecom.DisconnectCause; +import android.util.Pair; +import com.android.incallui.call.DialerCall; +import java.util.Locale; + +/** + * Wrapper class around @Code{android.telecom.DisconnectCause} to provide more information to user. + */ +public class DisconnectMessage { + + // Disconnect dialog catalog. Default error dialog MUST be last one. + private static final DisconnectDialog[] DISCONNECT_DIALOGS = + new DisconnectDialog[] { + new EnableWifiCallingPrompt(), new VideoCallNotAvailablePrompt(), new DefaultErrorDialog() + }; + + public final Dialog dialog; + public final CharSequence toastMessage; + private final DisconnectCause cause; + + public DisconnectMessage(Context context, DialerCall call) { + cause = call.getDisconnectCause(); + + for (DisconnectDialog disconnectDialog : DISCONNECT_DIALOGS) { + if (disconnectDialog.shouldShow(cause)) { + Pair<Dialog, CharSequence> pair = disconnectDialog.createDialog(context, call); + dialog = pair.first; + toastMessage = pair.second; + return; + } + } + dialog = null; + toastMessage = null; + } + + @Override + public String toString() { + return String.format( + Locale.ENGLISH, + "DisconnectMessage {code: %d, description: %s, reason: %s, message: %s}", + cause.getCode(), + cause.getDescription(), + cause.getReason(), + toastMessage); + } +} diff --git a/java/com/android/incallui/disconnectdialog/EnableWifiCallingPrompt.java b/java/com/android/incallui/disconnectdialog/EnableWifiCallingPrompt.java new file mode 100644 index 000000000..da0c9d6be --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/EnableWifiCallingPrompt.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui.disconnectdialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.support.annotation.NonNull; +import android.telecom.DisconnectCause; +import android.util.Pair; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.incallui.call.DialerCall; + +/** Prompts the user to enable Wi-Fi calling. */ +public class EnableWifiCallingPrompt implements DisconnectDialog { + // This is a hidden constant in android.telecom.DisconnectCause. Telecom sets this as a disconnect + // reason if it wants us to prompt the user to enable Wi-Fi calling. In Android-O we might + // consider using a more explicit way to signal this. + private static final String REASON_WIFI_ON_BUT_WFC_OFF = "REASON_WIFI_ON_BUT_WFC_OFF"; + private static final String ACTION_WIFI_CALLING_SETTINGS = + "android.settings.WIFI_CALLING_SETTINGS"; + private static final String ANDROID_SETTINGS_PACKAGE = "com.android.settings"; + + @Override + public boolean shouldShow(DisconnectCause disconnectCause) { + String reason = disconnectCause.getReason(); + if (reason.startsWith(REASON_WIFI_ON_BUT_WFC_OFF)) { + LogUtil.i( + "EnableWifiCallingPrompt.shouldShowPrompt", + "showing prompt for disconnect cause: %s", + reason); + return true; + } + return false; + } + + @Override + public Pair<Dialog, CharSequence> createDialog(final @NonNull Context context, DialerCall call) { + Assert.isNotNull(context); + DisconnectCause cause = call.getDisconnectCause(); + CharSequence message = cause.getDescription(); + Dialog dialog = + new AlertDialog.Builder(context) + .setMessage(message) + .setPositiveButton( + R.string.incall_enable_wifi_calling_button, + (OnClickListener) (dialog1, which) -> openWifiCallingSettings(context)) + .setNegativeButton(android.R.string.cancel, null) + .create(); + return new Pair<>(dialog, message); + } + + private static void openWifiCallingSettings(@NonNull Context context) { + LogUtil.i("EnableWifiCallingPrompt.openWifiCallingSettings", "opening settings"); + context.startActivity( + new Intent(ACTION_WIFI_CALLING_SETTINGS).setPackage(ANDROID_SETTINGS_PACKAGE)); + } +} diff --git a/java/com/android/incallui/disconnectdialog/VideoCallNotAvailablePrompt.java b/java/com/android/incallui/disconnectdialog/VideoCallNotAvailablePrompt.java new file mode 100644 index 000000000..34db976b2 --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/VideoCallNotAvailablePrompt.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui.disconnectdialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.NonNull; +import android.telecom.DisconnectCause; +import android.telecom.PhoneAccountHandle; +import android.util.Pair; +import com.android.dialer.callintent.CallInitiationType; +import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.common.LogUtil; +import com.android.dialer.util.DialerUtils; +import com.android.incallui.call.DialerCall; + +/** Prompt user to make voice call if video call is not currently available. */ +public class VideoCallNotAvailablePrompt implements DisconnectDialog { + + private static final String REASON_IMS_ACCESS_BLOCKED = "IMS_ACCESS_BLOCKED"; + + @Override + public boolean shouldShow(DisconnectCause disconnectCause) { + if (disconnectCause.getCode() == DisconnectCause.ERROR + && REASON_IMS_ACCESS_BLOCKED.equals(disconnectCause.getReason())) { + LogUtil.i( + "VideoCallNotAvailablePrompt.shouldShowPrompt", + "showing prompt for disconnect cause: %s", + disconnectCause.getReason()); + return true; + } else { + return false; + } + } + + @Override + public Pair<Dialog, CharSequence> createDialog(@NonNull Context context, DialerCall call) { + CharSequence title = context.getString(R.string.video_call_not_available_title); + + Dialog dialog = + new AlertDialog.Builder(context) + .setTitle(title) + .setMessage(context.getString(R.string.video_call_not_available_message)) + .setPositiveButton( + R.string.voice_call, + (dialog1, which) -> + makeVoiceCall(context, call.getNumber(), call.getAccountHandle())) + .setNegativeButton(android.R.string.cancel, null) + .create(); + return new Pair<>(dialog, title); + } + + private void makeVoiceCall(Context context, String number, PhoneAccountHandle accountHandle) { + LogUtil.enterBlock("VideoCallNotAvailablePrompt.makeVoiceCall"); + Intent intent = + new CallIntentBuilder(number, CallInitiationType.Type.IMS_VIDEO_BLOCKED_FALLBACK_TO_VOICE) + .setPhoneAccountHandle(accountHandle) + .build(); + DialerUtils.startActivityWithErrorToast(context, intent); + } +} diff --git a/java/com/android/incallui/disconnectdialog/res/values/strings.xml b/java/com/android/incallui/disconnectdialog/res/values/strings.xml new file mode 100644 index 000000000..91389db76 --- /dev/null +++ b/java/com/android/incallui/disconnectdialog/res/values/strings.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2017 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License + --> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- Button to enable Wi-Fi calling. This is displayed in a dialog after a phone call disconnects + because there is no cellular service. + [CHAR LIMIT=20] --> + <string name="incall_enable_wifi_calling_button">Enable</string> + + <!-- Title of alert dialog displayed when video call is not available. [CHAR LIMIT=NONE] --> + <string name="video_call_not_available_title">Video calling is currently not available</string> + <!-- Message of alert dialog displayed when video call is not available. [CHAR LIMIT=NONE] --> + <string name="video_call_not_available_message">Try calling again later or continue the call as a voice call.</string> + <!-- Voice call button label of alert dialog displayed when video call is not available. [CHAR LIMIT=20] --> + <string name="voice_call">Voice call</string> + +</resources> |