Home | History | Annotate | Download | only in disconnectdialog
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.incallui.disconnectdialog;
     18 
     19 import android.app.AlertDialog;
     20 import android.app.Dialog;
     21 import android.content.Context;
     22 import android.content.Intent;
     23 import android.support.annotation.NonNull;
     24 import android.telecom.DisconnectCause;
     25 import android.telecom.PhoneAccountHandle;
     26 import android.util.Pair;
     27 import com.android.contacts.common.compat.telecom.TelecomManagerCompat;
     28 import com.android.dialer.callintent.CallInitiationType;
     29 import com.android.dialer.callintent.CallIntentBuilder;
     30 import com.android.dialer.common.LogUtil;
     31 import com.android.dialer.util.DialerUtils;
     32 import com.android.incallui.call.DialerCall;
     33 
     34 /** Prompt user to make voice call if video call is not currently available. */
     35 public class VideoCallNotAvailablePrompt implements DisconnectDialog {
     36 
     37   @Override
     38   public boolean shouldShow(DisconnectCause disconnectCause) {
     39     if (disconnectCause.getCode() == DisconnectCause.ERROR
     40         && TelecomManagerCompat.REASON_IMS_ACCESS_BLOCKED.equals(disconnectCause.getReason())) {
     41       LogUtil.i(
     42           "VideoCallNotAvailablePrompt.shouldShowPrompt",
     43           "showing prompt for disconnect cause: %s",
     44           disconnectCause.getReason());
     45       return true;
     46     } else {
     47       return false;
     48     }
     49   }
     50 
     51   @Override
     52   public Pair<Dialog, CharSequence> createDialog(@NonNull Context context, DialerCall call) {
     53     CharSequence title = context.getString(R.string.video_call_not_available_title);
     54 
     55     Dialog dialog =
     56         new AlertDialog.Builder(context)
     57             .setTitle(title)
     58             .setMessage(context.getString(R.string.video_call_not_available_message))
     59             .setPositiveButton(
     60                 R.string.voice_call,
     61                 (dialog1, which) ->
     62                     makeVoiceCall(context, call.getNumber(), call.getAccountHandle()))
     63             .setNegativeButton(android.R.string.cancel, null)
     64             .create();
     65     return new Pair<>(dialog, title);
     66   }
     67 
     68   private void makeVoiceCall(Context context, String number, PhoneAccountHandle accountHandle) {
     69     LogUtil.enterBlock("VideoCallNotAvailablePrompt.makeVoiceCall");
     70     Intent intent =
     71         new CallIntentBuilder(number, CallInitiationType.Type.IMS_VIDEO_BLOCKED_FALLBACK_TO_VOICE)
     72             .setPhoneAccountHandle(accountHandle)
     73             .build();
     74     DialerUtils.startActivityWithErrorToast(context, intent);
     75   }
     76 }
     77