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.googlecode.android_scripting.facade.telephony;
18 
19 import android.telephony.ims.ProvisioningManager;
20 import android.telephony.ims.feature.MmTelFeature;
21 import android.telephony.ims.stub.ImsRegistrationImplBase;
22 
23 import com.googlecode.android_scripting.facade.FacadeManager;
24 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
25 import com.googlecode.android_scripting.rpc.Rpc;
26 import com.googlecode.android_scripting.rpc.RpcParameter;
27 
28 /**
29  * Exposes ProvisioningManager functionality
30  */
31 public class ProvisioningManagerFacade extends RpcReceiver {
32 
ProvisioningManagerFacade(FacadeManager manager)33     public ProvisioningManagerFacade(FacadeManager manager) {
34         super(manager);
35     }
36 
37     /**
38      * Get whether VoLTE, WFC, VT is provisioned on device
39      *
40      * @param subId The subscription ID of the sim you want to check
41      * @param capability includes voice, video, sms
42      * @param tech includes lte, iwlan
43      */
44     @Rpc(description = "Return True if Capability is provisioned on device.")
provisioningGetProvisioningStatusForCapability( @pcParametername = "subId") Integer subId, @RpcParameter(name = "capability") String capability, @RpcParameter(name = "tech") String tech)45     public boolean provisioningGetProvisioningStatusForCapability(
46                 @RpcParameter(name = "subId") Integer subId,
47                 @RpcParameter(name = "capability") String capability,
48                 @RpcParameter(name = "tech") String tech)
49             throws IllegalArgumentException {
50 
51         int capability_val;
52         int tech_val;
53 
54         switch (capability.toUpperCase()) {
55             case TelephonyConstants.CAPABILITY_TYPE_VOICE:
56                 capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE;
57                 break;
58             case TelephonyConstants.CAPABILITY_TYPE_VIDEO:
59                 capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO;
60                 break;
61             case TelephonyConstants.CAPABILITY_TYPE_UT:
62                 capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT;
63                 break;
64             case TelephonyConstants.CAPABILITY_TYPE_SMS:
65                 capability_val = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_SMS;
66                 break;
67             default:
68                 throw new IllegalArgumentException("Invalid CapabilityType");
69         }
70 
71         switch (tech.toUpperCase()) {
72             case TelephonyConstants.REGISTRATION_TECH_LTE:
73                 tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_LTE;
74                 break;
75             case TelephonyConstants.REGISTRATION_TECH_IWLAN:
76                 tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN;
77                 break;
78             case TelephonyConstants.REGISTRATION_TECH_NONE:
79                 tech_val = ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
80                 break;
81             default:
82                 throw new IllegalArgumentException("Invalid TechType");
83         }
84 
85         return ProvisioningManager.createForSubscriptionId(subId)
86             .getProvisioningStatusForCapability(capability_val, tech_val);
87     }
88 
89     /**
90      * Sets provisioned value for VoLTE, WFC, VT on device
91      *
92      * @param subId The subscription ID of the sim you want to set
93      * @param key includes volte, vt
94      * @param value includes enable, disable
95      */
96     @Rpc(description = "Returns CapabilityValue after setting on device.")
provisioningSetProvisioningIntValue( @pcParametername = "subId") Integer subId, @RpcParameter(name = "key") String key, @RpcParameter(name = "value") String value)97     public int provisioningSetProvisioningIntValue(
98                 @RpcParameter(name = "subId") Integer subId,
99                 @RpcParameter(name = "key") String key,
100                 @RpcParameter(name = "value") String value)
101             throws IllegalArgumentException {
102 
103         int capability_key;
104         int capability_val;
105 
106         switch (key.toUpperCase()) {
107             case TelephonyConstants.KEY_VOLTE_PROVISIONING_STATUS:
108                 capability_key = ProvisioningManager.KEY_VOLTE_PROVISIONING_STATUS;
109                 break;
110             case TelephonyConstants.KEY_VT_PROVISIONING_STATUS:
111                 capability_key = ProvisioningManager.KEY_VT_PROVISIONING_STATUS;
112                 break;
113             default:
114                 throw new IllegalArgumentException("Invalid Key");
115         }
116 
117         switch (value.toUpperCase()) {
118             case TelephonyConstants.PROVISIONING_VALUE_ENABLED:
119                 capability_val = ProvisioningManager.PROVISIONING_VALUE_ENABLED;
120                 break;
121             case TelephonyConstants.PROVISIONING_VALUE_DISABLED:
122                 capability_val = ProvisioningManager.PROVISIONING_VALUE_DISABLED;
123                 break;
124             default:
125                 throw new IllegalArgumentException("Invalid Value");
126         }
127 
128         return ProvisioningManager.createForSubscriptionId(subId)
129                     .setProvisioningIntValue(capability_key, capability_val);
130     }
131 
132     @Override
shutdown()133     public void shutdown() {
134 
135     }
136 }
137