1 /* 2 * Copyright (C) 2020 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.settings.network.ims; 18 19 import android.content.Context; 20 import android.telecom.TelecomManager; 21 import android.telephony.AccessNetworkConstants; 22 import android.telephony.SubscriptionManager; 23 import android.telephony.ims.ImsException; 24 import android.telephony.ims.feature.MmTelFeature; 25 import android.telephony.ims.stub.ImsRegistrationImplBase; 26 import android.util.Log; 27 28 import androidx.annotation.VisibleForTesting; 29 30 /** 31 * Controller class for querying VT status 32 */ 33 public class VtQueryImsState extends ImsQueryController { 34 35 private static final String LOG_TAG = "VtQueryImsState"; 36 37 private Context mContext; 38 private int mSubId; 39 40 /** 41 * Constructor 42 * 43 * @param context {@link Context} 44 * @param subId subscription's id 45 */ VtQueryImsState(Context context, int subId)46 public VtQueryImsState(Context context, int subId) { 47 super(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO, 48 ImsRegistrationImplBase.REGISTRATION_TECH_LTE, 49 AccessNetworkConstants.TRANSPORT_TYPE_WWAN); 50 mContext = context; 51 mSubId = subId; 52 } 53 54 /** 55 * Implementation of ImsQueryController#isEnabledByUser(int subId) 56 */ 57 @VisibleForTesting isEnabledByUser(int subId)58 boolean isEnabledByUser(int subId) { 59 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 60 return false; 61 } 62 return (new ImsQueryVtUserSetting(subId)).query(); 63 } 64 65 /** 66 * Check whether Video Call can be perform or not on this subscription 67 * 68 * @return true when Video Call can be performed, otherwise false 69 */ isReadyToVideoCall()70 public boolean isReadyToVideoCall() { 71 if (!isProvisionedOnDevice(mSubId)) { 72 return false; 73 } 74 75 try { 76 return isEnabledByPlatform(mSubId) && isServiceStateReady(mSubId); 77 } catch (InterruptedException | IllegalArgumentException | ImsException exception) { 78 Log.w(LOG_TAG, "fail to get Vt ready. subId=" + mSubId, exception); 79 } 80 return false; 81 } 82 83 /** 84 * Get allowance status for user to alter configuration 85 * 86 * @return true when changing configuration by user is allowed. 87 */ isAllowUserControl()88 public boolean isAllowUserControl() { 89 if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { 90 return false; 91 } 92 return ((!isTtyEnabled(mContext)) 93 || (isTtyOnVolteEnabled(mSubId))); 94 } 95 96 @VisibleForTesting isTtyEnabled(Context context)97 boolean isTtyEnabled(Context context) { 98 final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 99 return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); 100 } 101 102 /** 103 * Get user's configuration 104 * 105 * @return true when user's configuration is ON otherwise false. 106 */ isEnabledByUser()107 public boolean isEnabledByUser() { 108 if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { 109 return false; 110 } 111 return isEnabledByUser(mSubId); 112 } 113 } 114