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.telephony.ims.ProvisioningManager;
20 import android.telephony.ims.feature.MmTelFeature;
21 import android.telephony.ims.stub.ImsRegistrationImplBase;
22 import android.util.Log;
23 
24 
25 /**
26  * An {@link ImsQuery} for accessing IMS provision stat
27  */
28 public class ImsQueryProvisioningStat implements ImsQuery {
29 
30     private static final String LOG_TAG = "QueryPrivisioningStat";
31 
32     private volatile int mSubId;
33     private volatile int mCapability;
34     private volatile int mTech;
35 
36     /**
37      * Constructor
38      * @param subId subscription id
39      * @param capability {@link MmTelFeature.MmTelCapabilities#MmTelCapability}
40      * @param tech {@link ImsRegistrationImplBase#ImsRegistrationTech}
41      */
ImsQueryProvisioningStat(int subId, @MmTelFeature.MmTelCapabilities.MmTelCapability int capability, @ImsRegistrationImplBase.ImsRegistrationTech int tech)42     public ImsQueryProvisioningStat(int subId,
43             @MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
44             @ImsRegistrationImplBase.ImsRegistrationTech int tech) {
45         mSubId = subId;
46         mCapability = capability;
47         mTech = tech;
48     }
49 
50     /**
51      * Implementation of interface {@link ImsQuery#query()}
52      *
53      * @return result of query
54      */
query()55     public boolean query() {
56         try {
57             final ProvisioningManager privisionManager =
58                     ProvisioningManager.createForSubscriptionId(mSubId);
59             return privisionManager.getProvisioningStatusForCapability(mCapability, mTech);
60         } catch (IllegalArgumentException exception) {
61             Log.w(LOG_TAG, "fail to get Provisioning stat. subId=" + mSubId, exception);
62         }
63         return false;
64     }
65 }
66