• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static android.telephony.ims.ProvisioningManager.KEY_VOIMS_OPT_IN_STATUS;
20 
21 import android.content.Context;
22 import android.telecom.TelecomManager;
23 import android.telephony.AccessNetworkConstants;
24 import android.telephony.SubscriptionManager;
25 import android.telephony.ims.ImsException;
26 import android.telephony.ims.ProvisioningManager;
27 import android.telephony.ims.feature.MmTelFeature;
28 import android.telephony.ims.stub.ImsRegistrationImplBase;
29 import android.util.Log;
30 
31 import androidx.annotation.VisibleForTesting;
32 
33 /**
34  * Controller class for querying Volte status
35  */
36 public class VolteQueryImsState extends ImsQueryController {
37 
38     private static final String LOG_TAG = "VolteQueryImsState";
39 
40     private Context mContext;
41     private int mSubId;
42 
43     /**
44      * Constructor
45      *
46      * @param context {@link Context}
47      * @param subId subscription's id
48      */
VolteQueryImsState(Context context, int subId)49     public VolteQueryImsState(Context context, int subId) {
50         super(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
51                 ImsRegistrationImplBase.REGISTRATION_TECH_LTE,
52                 AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
53         mContext = context;
54         mSubId = subId;
55     }
56 
57     /**
58      * Implementation of ImsQueryController#isEnabledByUser(int subId)
59      */
60     @VisibleForTesting
isEnabledByUser(int subId)61     boolean isEnabledByUser(int subId) {
62         if (!SubscriptionManager.isValidSubscriptionId(subId)) {
63             return false;
64         }
65         return (new ImsQueryEnhanced4gLteModeUserSetting(subId)).query();
66     }
67 
68     /**
69      * Check whether VoLTE has been provisioned or not on this subscription
70      *
71      * @return true when VoLTE has been enabled, otherwise false
72      */
isVoLteProvisioned()73     public boolean isVoLteProvisioned() {
74         if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
75             return false;
76         }
77         if (!isProvisionedOnDevice(mSubId)) {
78             return false;
79         }
80         try {
81             return isEnabledByPlatform(mSubId);
82         } catch (InterruptedException | IllegalArgumentException | ImsException exception) {
83             Log.w(LOG_TAG, "fail to get VoLte supporting status. subId=" + mSubId, exception);
84         }
85         return false;
86     }
87 
88     /**
89      * Check whether VoLTE can be perform or not on this subscription
90      *
91      * @return true when VoLTE can be performed, otherwise false
92      */
isReadyToVoLte()93     public boolean isReadyToVoLte() {
94         if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
95             return false;
96         }
97         if (!isVoLteProvisioned()) {
98             return false;
99         }
100         try {
101             return isServiceStateReady(mSubId);
102         } catch (InterruptedException | IllegalArgumentException | ImsException exception) {
103             Log.w(LOG_TAG, "fail to get VoLte service status. subId=" + mSubId, exception);
104         }
105         return false;
106     }
107 
108     /**
109      * Get allowance status for user to alter configuration
110      *
111      * @return true when changing configuration by user is allowed.
112      */
isAllowUserControl()113     public boolean isAllowUserControl() {
114         if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
115             return false;
116         }
117 
118         return ((!isTtyEnabled(mContext))
119                 || (isTtyOnVolteEnabled(mSubId)));
120     }
121 
122     @VisibleForTesting
isTtyEnabled(Context context)123     boolean isTtyEnabled(Context context) {
124         final TelecomManager telecomManager = context.getSystemService(TelecomManager.class);
125         return (telecomManager.getCurrentTtyMode() != TelecomManager.TTY_MODE_OFF);
126     }
127 
128     /**
129      * Get user's configuration
130      *
131      * @return true when user's configuration is ON otherwise false.
132      */
isEnabledByUser()133     public boolean isEnabledByUser() {
134         if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
135             return false;
136         }
137         return isEnabledByUser(mSubId);
138     }
139 
140     /**
141      * Get VoIMS opt-in configuration.
142      *
143      * @return true when VoIMS opt-in has been enabled, otherwise false
144      */
isVoImsOptInEnabled()145     public boolean isVoImsOptInEnabled() {
146         int voImsOptInStatus = ProvisioningManager.createForSubscriptionId(mSubId)
147                 .getProvisioningIntValue(KEY_VOIMS_OPT_IN_STATUS);
148         return voImsOptInStatus == ProvisioningManager.PROVISIONING_VALUE_ENABLED;
149     }
150 }
151