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.dialer.precall.impl; 18 19 import android.content.Context; 20 import android.widget.Toast; 21 import com.android.dialer.callintent.CallIntentBuilder; 22 import com.android.dialer.precall.PreCallAction; 23 import com.android.dialer.precall.PreCallCoordinator; 24 import com.android.dialer.telecom.TelecomUtil; 25 26 /** Aborts call and show a toast if phone permissions are missing. */ 27 public class PermissionCheckAction implements PreCallAction { 28 29 @Override requiresUi(Context context, CallIntentBuilder builder)30 public boolean requiresUi(Context context, CallIntentBuilder builder) { 31 return !TelecomUtil.hasCallPhonePermission(context); 32 } 33 34 @Override runWithoutUi(Context context, CallIntentBuilder builder)35 public void runWithoutUi(Context context, CallIntentBuilder builder) {} 36 37 @Override runWithUi(PreCallCoordinator coordinator)38 public void runWithUi(PreCallCoordinator coordinator) { 39 if (!requiresUi(coordinator.getActivity(), coordinator.getBuilder())) { 40 return; 41 } 42 Toast.makeText( 43 coordinator.getActivity(), 44 coordinator 45 .getActivity() 46 .getString(R.string.pre_call_permission_check_no_phone_permission), 47 Toast.LENGTH_LONG) 48 .show(); 49 coordinator.abortCall(); 50 } 51 52 @Override onDiscard()53 public void onDiscard() {} 54 } 55