From da410d32f17dd823dba772181271ff55ee8e3eaf Mon Sep 17 00:00:00 2001 From: wangqi Date: Tue, 6 Mar 2018 16:51:38 -0800 Subject: Show a warning dialog about charges when user starts a video call The user starts a video call a warning dialog shall be presented. If the user presses "OK" with the "Do not show again" box selected, the dialog shall not be presented anymore. Test: manual - Verified that a warning dialog about charges is shown when a video call is started if KEY_SHOW_VIDEO_CALL_CHARGES_ALERT_DIALOG_BOOL is true. This is an upstream change from: https://android-review.googlesource.com/c/platform/packages/apps/Dialer/+/518977/8 Bug: 67832837 Test: partner manual test PiperOrigin-RevId: 188103414 Change-Id: I62628a32557297acaef096db90d2ddf049ef5017 --- .../video/impl/SurfaceViewVideoCallFragment.java | 3 + .../incallui/video/impl/VideoCallFragment.java | 29 +++++ .../impl/VideoChargesAlertDialogFragment.java | 141 +++++++++++++++++++++ .../res/layout/frag_video_charges_alert_dialog.xml | 51 ++++++++ .../incallui/video/impl/res/values/strings.xml | 6 + .../incallui/video/protocol/VideoCallScreen.java | 2 + 6 files changed, 232 insertions(+) create mode 100644 java/com/android/incallui/video/impl/VideoChargesAlertDialogFragment.java create mode 100644 java/com/android/incallui/video/impl/res/layout/frag_video_charges_alert_dialog.xml (limited to 'java/com/android/incallui/video') diff --git a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java index 28ee774ba..b97d2eb16 100644 --- a/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java +++ b/java/com/android/incallui/video/impl/SurfaceViewVideoCallFragment.java @@ -724,6 +724,9 @@ public class SurfaceViewVideoCallFragment extends Fragment return Assert.isNotNull(getArguments().getString(ARG_CALL_ID)); } + @Override + public void onHandoverFromWiFiToLte() {} + @Override public void showButton(@InCallButtonIds int buttonId, boolean show) { LogUtil.v( diff --git a/java/com/android/incallui/video/impl/VideoCallFragment.java b/java/com/android/incallui/video/impl/VideoCallFragment.java index 6b5a9797f..2a810cfcd 100644 --- a/java/com/android/incallui/video/impl/VideoCallFragment.java +++ b/java/com/android/incallui/video/impl/VideoCallFragment.java @@ -99,6 +99,8 @@ public class VideoCallFragment extends Fragment @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) static final String ARG_CALL_ID = "call_id"; + private static final String TAG_VIDEO_CHARGES_ALERT = "tag_video_charges_alert"; + @VisibleForTesting static final float BLUR_PREVIEW_RADIUS = 16.0f; @VisibleForTesting static final float BLUR_PREVIEW_SCALE_FACTOR = 1.0f; private static final float BLUR_REMOTE_RADIUS = 25.0f; @@ -108,6 +110,7 @@ public class VideoCallFragment extends Fragment private static final int CAMERA_PERMISSION_REQUEST_CODE = 1; private static final long CAMERA_PERMISSION_DIALOG_DELAY_IN_MILLIS = 2000L; private static final long VIDEO_OFF_VIEW_FADE_OUT_DELAY_IN_MILLIS = 2000L; + private static final long VIDEO_CHARGES_ALERT_DIALOG_DELAY_IN_MILLIS = 500L; private final ViewOutlineProvider circleOutlineProvider = new ViewOutlineProvider() { @@ -162,6 +165,24 @@ public class VideoCallFragment extends Fragment } }; + private final Runnable videoChargesAlertDialogRunnable = + () -> { + VideoChargesAlertDialogFragment existingVideoChargesAlertFragment = + (VideoChargesAlertDialogFragment) + getChildFragmentManager().findFragmentByTag(TAG_VIDEO_CHARGES_ALERT); + if (existingVideoChargesAlertFragment != null) { + LogUtil.i( + "VideoCallFragment.videoChargesAlertDialogRunnable", "already shown for this call"); + return; + } + + if (VideoChargesAlertDialogFragment.shouldShow(getContext(), getCallId())) { + LogUtil.i("VideoCallFragment.videoChargesAlertDialogRunnable", "showing dialog"); + VideoChargesAlertDialogFragment.newInstance(getCallId()) + .show(getChildFragmentManager(), TAG_VIDEO_CHARGES_ALERT); + } + }; + public static VideoCallFragment newInstance(String callId) { Bundle bundle = new Bundle(); bundle.putString(ARG_CALL_ID, Assert.isNotNull(callId)); @@ -352,6 +373,8 @@ public class VideoCallFragment extends Fragment inCallButtonUiDelegate.refreshMuteState(); videoCallScreenDelegate.onVideoCallScreenUiReady(); getView().postDelayed(cameraPermissionDialogRunnable, CAMERA_PERMISSION_DIALOG_DELAY_IN_MILLIS); + getView() + .postDelayed(videoChargesAlertDialogRunnable, VIDEO_CHARGES_ALERT_DIALOG_DELAY_IN_MILLIS); } @Override @@ -377,6 +400,7 @@ public class VideoCallFragment extends Fragment @Override public void onVideoScreenStop() { + getView().removeCallbacks(videoChargesAlertDialogRunnable); getView().removeCallbacks(cameraPermissionDialogRunnable); videoCallScreenDelegate.onVideoCallScreenUiUnready(); } @@ -767,6 +791,11 @@ public class VideoCallFragment extends Fragment return Assert.isNotNull(getArguments().getString(ARG_CALL_ID)); } + @Override + public void onHandoverFromWiFiToLte() { + getView().post(videoChargesAlertDialogRunnable); + } + @Override public void showButton(@InCallButtonIds int buttonId, boolean show) { LogUtil.v( diff --git a/java/com/android/incallui/video/impl/VideoChargesAlertDialogFragment.java b/java/com/android/incallui/video/impl/VideoChargesAlertDialogFragment.java new file mode 100644 index 000000000..6762a9d22 --- /dev/null +++ b/java/com/android/incallui/video/impl/VideoChargesAlertDialogFragment.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2018 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.video.impl; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.annotation.NonNull; +import android.support.annotation.VisibleForTesting; +import android.support.v4.app.DialogFragment; +import android.support.v4.os.UserManagerCompat; +import android.telecom.Call.Details; +import android.view.View; +import android.widget.CheckBox; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.incallui.call.CallList; +import com.android.incallui.call.DialerCall; + +/** Alert dialog for video charges. */ +public class VideoChargesAlertDialogFragment extends DialogFragment { + + /** Preference key for whether to show the alert dialog for video charges next time. */ + @VisibleForTesting + static final String KEY_DO_NOT_SHOW_VIDEO_CHARGES_ALERT = "key_do_not_show_video_charges_alert"; + + /** Key in the arguments bundle for call id. */ + private static final String ARG_CALL_ID = "call_id"; + + /** + * Returns {@code true} if an {@link VideoChargesAlertDialogFragment} should be shown. + * + *

Attempting to show an VideoChargesAlertDialogFragment when this method returns {@code false} + * will result in an {@link IllegalStateException}. + */ + public static boolean shouldShow(@NonNull Context context, String callId) { + DialerCall call = CallList.getInstance().getCallById(callId); + if (call == null) { + LogUtil.i("VideoChargesAlertDialogFragment.shouldShow", "null call"); + return false; + } + + if (call.hasProperty(Details.PROPERTY_WIFI)) { + return false; + } + + if (call.didDismissVideoChargesAlertDialog()) { + LogUtil.i( + "VideoChargesAlertDialogFragment.shouldShow", "The dialog has been dismissed by user"); + return false; + } + + if (!call.showVideoChargesAlertDialog()) { + return false; + } + + if (!UserManagerCompat.isUserUnlocked(context)) { + LogUtil.i("VideoChargesAlertDialogFragment.shouldShow", "user locked, returning false"); + return false; + } + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + if (preferences.getBoolean(KEY_DO_NOT_SHOW_VIDEO_CHARGES_ALERT, false)) { + LogUtil.i( + "VideoChargesAlertDialogFragment.shouldShow", + "Video charges alert has been disabled by user, returning false"); + return false; + } + + return true; + } + + /** + * Returns a new instance of {@link VideoChargesAlertDialogFragment} + * + *

Prefer this method over the default constructor. + */ + public static VideoChargesAlertDialogFragment newInstance(@NonNull String callId) { + VideoChargesAlertDialogFragment fragment = new VideoChargesAlertDialogFragment(); + Bundle args = new Bundle(); + args.putString(ARG_CALL_ID, Assert.isNotNull(callId)); + fragment.setArguments(args); + return fragment; + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle bundle) { + super.onCreateDialog(bundle); + + if (!VideoChargesAlertDialogFragment.shouldShow( + getActivity(), getArguments().getString(ARG_CALL_ID))) { + throw new IllegalStateException( + "shouldShow indicated VideoChargesAlertDialogFragment should not have showed"); + } + + View dialogView = View.inflate(getActivity(), R.layout.frag_video_charges_alert_dialog, null); + + CheckBox alertCheckBox = dialogView.findViewById(R.id.do_not_show); + + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + AlertDialog alertDialog = + new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme) + .setView(dialogView) + .setPositiveButton( + android.R.string.ok, + (dialog, which) -> onPositiveButtonClicked(preferences, alertCheckBox.isChecked())) + .create(); + this.setCancelable(false); + return alertDialog; + } + + private void onPositiveButtonClicked(@NonNull SharedPreferences preferences, boolean isChecked) { + LogUtil.i( + "VideoChargesAlertDialogFragment.onPositiveButtonClicked", "isChecked: %b", isChecked); + preferences.edit().putBoolean(KEY_DO_NOT_SHOW_VIDEO_CHARGES_ALERT, isChecked).apply(); + + DialerCall dialerCall = + CallList.getInstance().getCallById(getArguments().getString(ARG_CALL_ID)); + if (dialerCall != null) { + dialerCall.setDidDismissVideoChargesAlertDialog(true); + } + } +} diff --git a/java/com/android/incallui/video/impl/res/layout/frag_video_charges_alert_dialog.xml b/java/com/android/incallui/video/impl/res/layout/frag_video_charges_alert_dialog.xml new file mode 100644 index 000000000..a547c7d69 --- /dev/null +++ b/java/com/android/incallui/video/impl/res/layout/frag_video_charges_alert_dialog.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/java/com/android/incallui/video/impl/res/values/strings.xml b/java/com/android/incallui/video/impl/res/values/strings.xml index 58ea8bde7..6c90af5f3 100644 --- a/java/com/android/incallui/video/impl/res/values/strings.xml +++ b/java/com/android/incallui/video/impl/res/values/strings.xml @@ -29,4 +29,10 @@ Call resumed + + Video calls made over the mobile network use both data and voice minutes. Charges may apply. + + + Do not show again + diff --git a/java/com/android/incallui/video/protocol/VideoCallScreen.java b/java/com/android/incallui/video/protocol/VideoCallScreen.java index bad050cd1..582d4c64b 100644 --- a/java/com/android/incallui/video/protocol/VideoCallScreen.java +++ b/java/com/android/incallui/video/protocol/VideoCallScreen.java @@ -39,4 +39,6 @@ public interface VideoCallScreen { Fragment getVideoCallScreenFragment(); String getCallId(); + + void onHandoverFromWiFiToLte(); } -- cgit v1.2.3