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.SubscriptionManager; 22 23 import androidx.annotation.VisibleForTesting; 24 25 /** 26 * Controller class for querying VT status 27 */ 28 public class VtQueryImsState { 29 30 private final Context mContext; 31 private final int mSubId; 32 33 /** 34 * Constructor 35 * 36 * @param context {@link Context} 37 * @param subId subscription's id 38 */ VtQueryImsState(Context context, int subId)39 public VtQueryImsState(Context context, int subId) { 40 mContext = context; 41 mSubId = subId; 42 } 43 44 /** 45 * Implementation of ImsQueryController#isEnabledByUser(int subId) 46 */ 47 @VisibleForTesting isEnabledByUser(int subId)48 boolean isEnabledByUser(int subId) { 49 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 50 return false; 51 } 52 return (new ImsQueryVtUserSetting(subId)).query(); 53 } 54 55 /** 56 * Get allowance status for user to alter configuration 57 * 58 * @return true when changing configuration by user is allowed. 59 */ isAllowUserControl()60 public boolean isAllowUserControl() { 61 if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { 62 return false; 63 } 64 return !isTtyEnabled(mContext) || new ImsQueryTtyOnVolteStat(mSubId).query(); 65 } 66 67 @VisibleForTesting isTtyEnabled(Context context)68 boolean isTtyEnabled(Context context) { 69 final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 70 return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF); 71 } 72 73 /** 74 * Get user's configuration 75 * 76 * @return true when user's configuration is ON otherwise false. 77 */ isEnabledByUser()78 public boolean isEnabledByUser() { 79 if (!SubscriptionManager.isValidSubscriptionId(mSubId)) { 80 return false; 81 } 82 return isEnabledByUser(mSubId); 83 } 84 } 85